Answer a question

I've got a file in the package with 'test' in its name and when I run pytest I got an error

import file mismatch:
imported module 'my_project.my_file_test' has this __file__ attribute:
  /my_project/src/my_project/build/lib/python2.7/site-packages/foo/my_file_test.py
which is not the same as the test file we want to collect:
  /my_project/src/my_project/build/private/python2.7/lib/foo/my_file_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

If I remove 'test' from the file it works fine but unfortunately I can't change it.

So the question is how to tell pytest to ignore this file?

Answers

So finally it was easy, I just had to add test file pattern to the pytest.ini file:

python_files = test_*.py

so pytest stopped looking for files with test in the end of the name what it did by default.

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐