PyCharm Django test ModuleNotFoundError
|___sb_website | |___article | | |__...py | |___home | | |__...py | |___sb_website | | |__dev_settings.py | | |__...py | |__manage.py | |__...py
My django project development settings are
dev_settings.py. 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\manage.py I get the following Error:
ERROR: sb_website.article (unittest.loader._FailedTest) ImportError: Failed to import test module: sb_website.article.
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.
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
manage.py test command and executing it tried to import tests and found a
__init__.py in the root folder.
By removing the
__ini__.py 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