pytest—默认测试用例规则

1、​文件命名规则:

  • 测试文件需要以 test_ 开头或以 _test.py 结尾。
  • 例如:
  1. 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

1. 基本相等性断言

2. 布尔值断言

3. 比较断言

4. 成员关系断言

5. 异常断言

6. 近似相等断言

posted @ 2025-05-09 08:52  快乐的小太阳  阅读(47)  评论(0)    收藏  举报