question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing package causes Test Explorer to incorrectly report missing test class in module

See original GitHub issue

When a unittest.TestCase subclass in a module has a test method that tests functionality depending on a missing package, instead of reporting the missing package when the test is run, it reports the test class as missing:

Message: ‘module’ object has no attribute ‘Test_Foo’

This is misleading, and does not help diagnose the actual problem.

To recreate:

  1. Create a new python project (File->New Project->Python Application)
  2. Add a virtual environment for the project (Solution Exporer->Right Click on Python Environments->Add Virtual Environment
  3. Add a module, and to that add a function that is dependent on an additional package (do NOT add that package to the environment: Foo.py
  4. Add a test class within that module, and add a method that calls the function dependent on the missing package Test_Foo.py
  5. The function appears in the Test Explorer. Run it.
  6. Note that rather than reporting the missing package, the Test Explorer reports the test class as missing:

`Test Name: test_do_ping Test FullName: Foo\Test_Foo.py::Test_Foo::test_do_ping Test Source: F:\Win7\Users\Matt\Desktop\PythonApplication1\PythonApplication1\Foo\Test_Foo.py : line 6 Test Outcome: Failed Test Duration: 0:00:00

Result StackTrace: File “C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\visualstudio_py_testlauncher.py”, line 269, in main for loaded_test in unittest.defaultTestLoader.loadTestsFromName(test): File “C:\Python27amd64\Lib\unittest\loader.py”, line 100, in loadTestsFromName parent, obj = obj, getattr(obj, part) AttributeError: ‘module’ object has no attribute ‘Test_Foo’ Result Message: ‘module’ object has no attribute ‘Test_Foo’ Result StandardError: Traceback (most recent call last): File “C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\visualstudio_py_testlauncher.py”, line 269, in main for loaded_test in unittest.defaultTestLoader.loadTestsFromName(test): File “C:\Python27amd64\Lib\unittest\loader.py”, line 100, in loadTestsFromName parent, obj = obj, getattr(obj, part) AttributeError: ‘module’ object has no attribute ‘Test_Foo’

`

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
zoobacommented, Aug 24, 2017

You’re right, though I’m not sure whether this is our fault or a Python bug.

Our static code analysis ignores (most) imports when determining which tests exist, and it seems that the Python 2.7 unittest module doesn’t properly expose runtime errors.

But we may be able to catch the AttributeError and do some extra runtime analysis to see whether the module failed to be imported. However, at this stage it’s likely that the error is already lost, so the best we can likely do is report that it failed to import for some unknown reason. (Attempting to import the module ourselves before unittest does could cause all sorts of other breakage, so I don’t want to do that.)

Running the file directly using “Start with/without debugging” should show the error, so perhaps we could recommend that as the next step in our error message?

0reactions
zoobacommented, Sep 15, 2017

We’ve decided that this issue is not a high enough priority for now, and so we are closing it to keep our tracker clean. Please reopen with new examples if it continues to be a problem in the latest update.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing package causes Test Explorer to incorrectly report ...
TestCase subclass in a module has a test method that tests functionality depending on a missing package, instead of reporting the missing ......
Read more >
Linking error clears the Test Explorer - Developer Community
If a build fails with a compilation error, the Test Explorer retains all the test info. If it fails with a linking error,...
Read more >
Tests not running in Test Explorer - visual studio
Since I got here with this kind of error I post my problem/solution: Symptoms: Not all tests running, but they didn't depend per...
Read more >
Run unit tests with Test Explorer - Visual Studio (Windows)
Test Explorer can run tests from multiple test projects in a solution and from test classes that are part of the production code...
Read more >
Unit Testing and Coding: Why Testable Code Matters
Having difficulty testing their own or someone else's code, developers often think that their struggles are caused by a lack of some fundamental...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found