Pytest运行及控制台输出信息

阅读 54

2022-06-17

运行一个简单的用例:

#cd code/ch1/test_one.py
def test_passing():
assert (1, 2, 3) == (1, 2, 3)

运行结果及说明:

Pytest运行及控制台输出信息_用例

测试运行可能出现的结果总结:

Pytest运行及控制台输出信息_不执行_02

 举例:

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)

运行结果:

Pytest运行及控制台输出信息_用例_03

去期待陌生,去拥抱惊喜。

精彩评论(0)

0 0 举报