`python m pytest`vs virtualenv中的pytest?

2024-06-16 10:36:36 发布

您现在位置:Python中文网/ 问答频道 /正文

在我以前的虚拟环境中,我可以直接执行pytest tests/unit/。你知道吗

然后我把我的环境搞砸了,不得不删除并重新安装我的.venv

然后在我激活新的.venv并重新安装所有软件包之后,我尝试了pytest tests/unit/,但出现了以下错误:

(.venv) john@MacBook-Pro:~/myproject$ pytest tests/unit/nti/ -p no:warnings 
-bash: /usr/local/bin/pytest: /usr/local/opt/python/bin/python3.6: bad interpreter: No such file or directory

经过一些痛苦的试验后,我发现我可以用以下方法运行测试:

(.venv) john@MacBook-Pro:~/myproject$ python -m pytest tests/unit/nti/ -p no:warnings

那么,python -m pytestpytest之间有什么区别呢?为什么pytest不起作用,但python -m pytest很好?你知道吗


Tags: nobinvenvpytestusrlocalmyproject虚拟环境