我想了解在IT技术中运行以下两种命令的区别:
$ pytest
and
$ python -m pytest tests
我正在Mac上的虚拟环境中工作。 第一个解决方案给了我一个错误:
ModuleNotFoundError: No module named 'app'
第二种解决方案可以正常工作。
为什么第二种解决方案可行而第一种不行? 我如何仅仅使用
$ pytest
就能使它起作用?我的文件夹结构:
├── app.py
├── requirements.txt
├── templates
├── tests
│ ├── conftest.py
│ ├── functional
│ │ ├── __init__.py
│ │ └── test_s.py
│ └── unit
│ ├── __init__.py
│ └── test_app.py
└── venv
在 test_app.py 中,这行代码失败了:
from app import app
pytest
可能并不等同于python -m pytest
。你应该验证which pytest
指向的文件可以被你的 Python 安装访问到。例如,在相同的虚拟环境/相同的 Python 安装中。 - Leggy