0

In my PyCharm (2016.3.3) project I have a package folder called 'tests', which holds some test modules (using unittest), e.g. 'test_A.py,' 'test_B.py.'

When I try to run the tests in one of these modules, or all tests in the entire 'tests' package, I get a nose_helper.failure.Failure due to AttributeError: 'module' object has no attribute 'test_A' (and same for the other test modules).

When I run the modules outside PyCharm they work without issue.

Does anyone know the reason, and how to solve this?

There are many similar questions here, e.g. 1, 2, 3, etc., but none of those solved my issue.

djvg
  • 11,722
  • 5
  • 72
  • 103

1 Answers1

0

No idea as to the exact cause, but in my PyCharm (2016.3.3) I was able to solve the issue by editing the run configuration:

From the menu bar select Run->Edit Configurations, then select your configuration, and in the "Configuration" tab under "Unittests" check "Inspect only subclasses of unittest.TestCase."

To make this default: Run -> Edit Configurations, then select Defaults->Python tests->Unittests, and again check the same box.

This answer was based on an ancient PyCharm support post.

--edit--

This also happens (in PyCharm 2018.3) if a test module tries to import a non-existent class, e.g. (using django) from myapp.models import MyModelA, MyModelB where MyModelB does not exist. Fixing the import should resolve the issue, in this case.

djvg
  • 11,722
  • 5
  • 72
  • 103