将非断言失败视为测试错误的pytest插件。
pytest-finer-verdicts的Python项目详细描述
pytest精细判决
将非断言失败视为测试错误的pytest插件。
获取插件
插件可以通过pip install pytest-finer-verdicts安装。 同样,也可以通过 pip uninstall pytest-finer-verdicts。
使用量
请考虑文件test.py中的以下片段(可用 temp/test.py在存储库中)。
import pytest def test_pass(): assert 70 <= 75 def test_fail(): assert 75 <= 70 def test_error(): raise RuntimeError() def test_pytest_fail(): pytest.fail("Fail") def test_pytest_raises(): with pytest.raises(ValueError): raise IndexError()
不带pytest finer verdicts插件,py.test test.py -v将 产生以下输出。
collected 5 items test.py::test_pass PASSED test.py::test_fail FAILED test.py::test_error ERROR test.py::test_pytest_fail FAILED test.py::test_pytest_raises ERROR ================================== ERRORS =================================== _______________________ ERROR at setup of test_error ________________________ def test_error(): > raise RuntimeError() E RuntimeError test.py:13: RuntimeError ___________________ ERROR at setup of test_pytest_raises ____________________ def test_pytest_raises(): with pytest.raises(ValueError): > raise IndexError() E IndexError test.py:22: IndexError ================================= FAILURES ================================== _________________________________ test_fail _________________________________ def test_fail(): > assert 75 <= 70 E assert 75 <= 70 test.py:9: AssertionError _____________________________ test_pytest_fail ______________________________ def test_pytest_fail(): > pytest.fail("Fail") E Failed: Fail test.py:17: Failed ================ 2 failed, 1 passed, 2 error in 0.05 seconds ================
注意test_error和test_pytest_raises如何标记为 插件测试错误。
归因
版权所有(c)2016,Venkatesh Prasad Ranganath
根据BSD 3条款“新”或“修订”许可证(https://choosealicense.com/licenses/bsd-3-clause/)
作者:venkatesh prasad ranganath