Pytest 会自动扫描项目中以 test_开头或以_test结尾的文件,读取文件中 test_ 开头的函数和以 Test 开头的类中的函数,识别为测试用例,自动执行!
test_
_test
Test
终端执行pytest, 会自动找到了所有 test_ 开头的函数并执行了它们!
pytest
def test_add(): assert 1 + 1 == 2
当你运行 pytest的时候,TestCalculator 类里的 test_add 函数就会被执行!
TestCalculator
test_add
class TestCalculator: def abc(self): assert 1 + 1 == 2 def test_add(self): assert 1 + 1 > 2