我从这里安装了 pytest 插件:http://pypi.python.org/pypi/pytest-cov .然后我有一个简单的测试代码:
pytest.py:
class TestNumbers:
def test_int_float(self):
assert 1 == 1.0
def test_int_str(self):
assert 1 == 1
我尝试使用命令对其进行测试:py.test --cov-report term --cov pytest.py
。但它不起作用。即使我给出了 pytest.py 的整个绝对路径,它仍然没有数据可供收集。但是,如果我使用 py.test pytest.py
,它肯定测试正常。
我对这个问题很困惑,感谢帮助。
最佳答案
尝试:
py.test --cov-report term --cov=. test.py
--cov
参数采用一个参数说明要覆盖哪些路径。在您的示例中,--cov
将使用 test.py
,但是 py.test 没有关于要测试哪些文件的参数。
更新:正如@hpk42 指出的那样,您需要将您的示例称为pytest.py
以外的名称。当我在本地执行此操作时,我将其称为 test.py
。
关于python - pytest 和 coverage 组合不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13621466/