我正在对 python 包进行测试,并尝试使用 pytest 进行测试。
该项目具有以下架构:
- package_name/
- __init__.py
- file1.py
- file2.py
- ...
- 测试/
- test_file1.py
- test_file2.py
- ...
- setup.py
- setup.cfg
- .coveragerc
如何设置 pytest 以使用单个命令启动所有测试,例如:
coverage run setup.py test
我尝试了一些设置,但是 pytest 似乎没有在 tests/ 目录中找到测试文件。
最佳答案
您是否尝试运行命令 pytest tests/
?
您也可以尝试使用标记测试调用:
@pytest.mark.my_tests
class TestsFilaA:
def test_something():
pass
def test_something_else():
pass
@pytest.mark.my_tests
class TestsFilaB:
def test_something_b():
pass
def test_something_else_b():
pass
并运行命令pytest -v -m my_tests
关于python - 如何设置 coveragerc 和/或 setup.cfg 以测试具有特定测试位置的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49853782/