Reputation: 97
When running the complete test with command python -m pytest tests
, it fails with import file mismatch error.
import file mismatch:
imported module 'test_simplifyvcf_integrations' has this __file__ attribute:
/home/promechpc5/Desktop/VCF-SimplifyDev/tests/test_integrations/test_simplifyvcf_integrations.py
which is not the same as the test file we want to collect:
/home/promechpc5/Desktop/VCF-SimplifyDev/tests/testfiles/TestFullApp/test_simplifyvcf_integrations.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Here, the errors are shown is test_simplifyvcf_integration.py, which is under tests folder. But when I run test separately with command python -m pytest tests/test_integrations/test_simplifyvcf_integrations.py
, it pass all the test.
Upvotes: 7
Views: 3154
Reputation: 70127
The solution here is in the error message:
and/or use a unique basename for your test file modules
you have to make sure you have unique module names inside your tests -- pytest will hoist them all into a top level namespace unless you add __init__.py
files such that they are different packages
So your options are:
__init__.py
filesUpvotes: 11
Reputation: 169
Well this has been an issue specifically related to pytest so you shouldn't worry much about because it's only related to cached files.
step 1 remove all __pycache__
folders from your test directory.
step 2 add the following snippet in your bashrc/zshrc file depending on which you use to stop generating those caches.
export PYTHONDONTWRITEBYTECODE=1
Upvotes: 0