运行一个简单的用例:

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

运行结果及说明:

Pytest运行及控制台输出信息

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

Pytest运行及控制台输出信息

 举例:

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运行及控制台输出信息

相关文章:

  • 2021-08-24
  • 2022-12-23
  • 2021-05-07
  • 2022-12-23
  • 2021-05-25
  • 2021-08-12
  • 2022-12-23
  • 2021-10-25
猜你喜欢
  • 2021-12-11
  • 2021-11-29
  • 2021-10-07
  • 2021-11-20
  • 2022-02-09
  • 2022-01-28
相关资源
相似解决方案