运行一个简单的用例:
#cd code/ch1/test_one.py
def test_passing():
assert (1, 2, 3) == (1, 2, 3)
运行结果及说明:
测试运行可能出现的结果总结(上图6、7运行结果列举)
import pytest
#测试通过
def test_passing():
assert (1, 2, 3) == (1, 2, 3)
#测试失败
def test_failing():
assert (1, 2, 3) == (3, 2, 1)
#跳过不执行
@pytest.mark.skip()
def test_skip():
assert (1, 2, 3) == (3, 2, 1)
#预期失败,确实失败
@pytest.mark.xfail()
def test_xfail():
assert (1, 2, 3) == (3, 2, 1)
#预期失败,但是结果pass
@pytest.mark.xfail()
def test_xpass():
assert (1, 2, 3) == (1, 2, 3)