PyCharm Django test ModuleNotFoundError

Project tree:

|   |___article
|   |   |
|   |___home
|   |   |
|   |___sb_website
|   |   |
|   |   |
|   |
|   |

My django project development settings are I want to run my tests against these settings.

When I use a Python configuration in PyCharm with these parameters test --settings=sb_website.dev_settings, script path ..\sb_website\ I get the following Error: ERROR: sb_website.article (unittest.loader._FailedTest) ImportError: Failed to import test module: sb_website.article. Same for sb_website.home and sb_website.sb_website

If use a Django Test configuration in PyCharm modules are imported and tests run fine.

I'd like to learn the root cause of my problem as it is not the first time I faced this.

What I tried: changed all imports to explicit imports, e.g. *.models to home.models

The issue was not related to PyCharm, the answer why there was a difference between the Python configuration and Django Test configuration was that the Python configuration pointed directly to the test target. Django Test configuration uses the test command and executing it tried to import tests and found a in the root folder.

By removing the in my root folder of sb_website the modules were found correctly and tests ran through. The answer was found here Running django tests fails

Back to Top