Python中如何运行单元测试文件?
项目结构如下:
├── app
│ ├── __init__.py
│ └── utils.py
├── tests
│ ├── test_app.py
app/utils的内容如下:
class A:
pass
以tests/test_app内容如下:
from app.utils import A
def test_app():
pass
直接运行py.test tests/test_app.py,会报找不到 app 这个模块,请问需要怎么修改,才能运行 tests 下面的测试。
Python中如何运行单元测试文件?
8 回复
lz 可以去搜一下 python 包管理 相对路径 绝对路径 ,搜完之后看看能不能解决~
app 的 父目录里运行 python -m unittest tests.test_app
PYTHONPATH=. pytest tests/test_app.py
直接上 nose
tests 目录下建一个 init.py
https://docs.pytest.org/en/latest/pythonpath.html
感谢


