Why can't I run my tests with `python manage.py test` command?

Hi there,

I have the following hierarchy of my project files and folders:

------------------test_models.py  # THIS IS MY TEST FILE

and I have the following statement(s) in my settings.py:

BASE_DIR = Path(__file__).resolve().parent.parent
sys.path.append(str(BASE_DIR / 'apps'))

Despite having added apps in the path as you can see above settings.py, why I can’t run my tests with python manage.py test, but can run with python manage.py test apps/accounts/tests/ command?

Try adding a __init__.py within your tests dir. Without it the test runner will skip the directry because it does not consider it a package.

@run_the_race I have __init.py__, just forgot to write in hierarchy. Moreover, you missed to read my full question. I said:

So, can you help me now?

Moreover your assumption about me missing it is false. if you were missing __init__.py if could still be the case for your issue, because when you explicitly tell it the path then it finds it, and currently it is not finding because it does not see it as a module.

Does apps and [APP-NAME] both have a __init__.py file too?

1 Like

@run_the_race apps does not have but [APP-NAME] has __init__.py file.

UPDATE: I added __init__.py in apps folder and also made migrations and migrated the upgrades to database, after this I tried python manage.py test and it ran all the tests.