Pytest 单元测试框架之断言

1、Pytest 中断言只能通过 assert 断言

  • 断言为真 True
  • 断言为假 False / not True
  • 断言包含 a in b
  • 断言相等 a == b
  • 断言不等 a != b
import pytest

def test_true():
    assert True

def test_false01():
    assert not True

def test_false02():
    assert False

def test_in():
    res = '{"username":"python"}'
    assert "python" in res

def test_equal():
    assert 1 == 1

def test_not_equal():
    assert 1 != 2

if __name__ == '__main__':
    pytest.main(["-sv","test_demo2.py"])

# 结果如下
test_demo2.py::test_true PASSED
test_demo2.py::test_false01 FAILED
test_demo2.py::test_false02 FAILED
test_demo2.py::test_in PASSED
test_demo2.py::test_equal PASSED
test_demo2.py::test_not_equal PASSED

 

posted @ 2020-07-02 16:23  一个老宅男  阅读(730)  评论(0编辑  收藏  举报