我正在python包上实现测试,我尝试使用pytest进行测试。
该项目具有以下体系结构:
-
package_name/
- __init__.py
- file1.py
- file2.py
- 。
-
测试/
- test_file1.py
- test_file2.py
- 。
- setup.py
- 设置.cfg
- .覆盖率
如何设置 pytest 以使用单个命令启动所有测试,例如:
coverage run setup.py test
我尝试了一些设置,但是似乎pytest在test/目录中找不到测试文件。
您是否尝试运行命令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