pytest—默认测试用例规则
1、文件命名规则:
- 测试文件需要以
test_开头或以_test.py结尾。 - 例如:
test_sample.py或sample_test.py。
2、函数命名规则:
- 测试函数需要以
test_开头。
- 例如:
def test_addition():
assert 1 + 1 == 2
3、类命名规则:
- 测试类需要以
Test开头,且类中的测试方法需要以test_开头,且不包含init方法。 - 例如:
class TestMath:
def test_addition(self):
assert 1 + 1 == 2

浙公网安备 33010602011771号