環境
- python 2.7 虛擬環境下已經安裝pytest 4.6.11
- 文件結構:
./src/__init__.py./src/main.py./tests/__init__.py./tests/one/__init__.py./tests/one/test_one.py - 在
./tests/one/test_one.py第一行加入from src import main - 項目根目錄運行
pytest出現錯誤No module named src
解決
python -m pytest
關於 python -m pytest 和 pytest 的區別
- 前者會將當前目錄加入
sys.path - https://docs.pytest.org/en/6.2.x/pythonpath.html#pytest-vs-python-m-pytest
