我有这个结构。
/bin
__init__.py
run_test.py (call pytest.main)
/tests
__init__.py
test_xyz.py
如果我只是通过 pytest.main() 调用 run_test.py,它不会调用“tests”模块中的测试。我尝试传递几个参数,如 module="tests"等,但它们不起作用。我必须完全取消自动发现并使用套件参数来获取任何测试。
我错过了什么?我试图遍历 pytest 模块中的代码,但它太复杂而无法理解。而且文档非常糟糕。
最佳答案
您可以传递要执行的内容的完整路径。
import pytest
pytest_args = [
'/tests',
# other tests here...
]
pytest.main(pytest_args)
这将执行目录中找到的所有测试,
没有必要有
/tests/__init__.py
关于python - py.test main() 调用示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28652315/