我想这是一个非常具体的情况,但我会提出这个问题,因为我没有找到相关的答案并且可能对其他人有用。
情况是这样的:
- Windows 是主机操作系统。
有一个 Ubuntu VirtualBox(用 vagrant 创建)。
我的 django 项目文件夹在 windows 和 ubuntu 之间共享。
我在 ubuntu 和 windows 上的 virtualenv 上都安装了 pytest(通过 pytest-django)。
- 如果我
pytest
从 windows virtualenv 运行命令,测试运行得很好 - 但是在 ubuntu vm 终端中,我不能只运行
pytest
命令,因为我收到错误:当前未安装程序 'pytest'。 - 我可以用
python -m pytest
. 但在这种情况下,我得到import file mismatch
错误:
=========================错误=======================
_____________ ERROR collecting my_django_app/tests.py ____________
import file mismatch:
imported module 'my_django_app.tests' has this **__file__** attribute:
C:\virtualEnvs\my_env\project_src\my_django_app\tests.py
which is not the same as the test file we want to collect:
/vagrant/projects/project_src/my_django_app/tests.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
信息很清楚,但我不知道如何克服这个问题。
我使用 python 2.7.9 并且没有pycache文件夹(也没有 ant .pyc 编译文件)。