pytest标记预期会失败的测试xfail
import pytest class TestClass: @pytest.mark.xfail(reason="预期失败") def test_one(self): assert True @pytest.mark.xfail(reason="预期失败") def test_two(self): assert False def test_three(self): assert True
pytest test_demo5.py
=== test session starts ====
collected 3 items
test_demo5.py Xx.
=== 1 passed, 1 xfailed, 1 xpassed in 0.12 seconds ===
pytest -v test_demo5.py
=== test session starts ===
collected 3 items
test_demo5.py::TestClass::test_one XPASS
test_demo5.py::TestClass::test_two XFAIL
test_demo5.py::TestClass::test_three PASSED
=== 1 passed, 1 xfailed, 1 xpassed in 0.08 seconds ===
x表示XFAIL,预期失败,实际也失败
X表示XPASS,预期失败,实际运行没有失败
本文来自博客园,作者:OTAKU_nicole,转载请注明原文链接:https://www.cnblogs.com/nicole-zhang/p/11139906.html