I stumbled into a strange error when running pytest in a side-project:
import file mismatch: imported module 'test_comments' has this __file__ attribute: /<root>/django-peterbecom/peterbecom/api/tests/test_comments.py which is not the same as the test file we want to collect: /<root>/django-peterbecom/peterbecom/publicapi/tests/test_comments.py HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
I desperately made sure I deleted every __pycache__ directory and every *.pyc file. I also ran rm -fr .pytest_cache.
It was strange because I knew I had, in the past, had two files called exactly the same. E.g. test_utils.py.
Turns out, you can have two test_something.py called exactly the same but they must both sit in a directory that has a __init__.py.
So there was nothing wrong with /<root>/django-peterbecom/peterbecom/api/tests/test_comments.py. I just had to do:
touch /<root>/django-peterbecom/peterbecom/api/tests/__init__.py
...and the problem got solved.
Comments