import pytestdef setup_module(): print('整个模块.py开始')def teardown_module(): print('整个模块的.py结束')def setup_function(): print('不在类中的函数前')def teardown_function(): print('不在类中的函数后')def test_w_one(): print('不在类中的方法1')def test_w_two(): print('不在类中的方法2')class TestClass: def setup_class(self): print('类前面') def teardown_class(self): print('类之后') def setup_method(self): print('方法前') def teardown_method(self): print('方法后') def test_one(self): x='this' assert 'h' in x def test_two(self): x='hello' assert 'h4'==x def test_three(self): a='hello' b='hello world' assert a in bif __name__ == '__main__': pytest.main("-s -v","pytestDemo.py")
整个模块.py开始
不在类中的函数前
不在类中的方法1
不在类中的函数后
pytestDemo.py::test_w_one ✓ 20% ██ 不在类中的函数前
不在类中的方法2
不在类中的函数后
pytestDemo.py::test_w_two ✓ 40% ████ 类前面
方法前
方法后
pytestDemo.py::TestClass.test_one ✓ 60% ██████ 方法前
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― TestClass.test_two ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
self = <pytest_2.pytestDemo.TestClass object at 0x105b0f438>
def test_two(self):
x='hello'
> assert 'h4'==x
E AssertionError: assert 'h4' == 'hello'
E - h4
E + hello
pytestDemo.py:39: AssertionError
方法后
pytestDemo.py::TestClass.test_two ⨯ 80% ████████ 方法前
方法后
类之后
整个模块的.py结束
pytestDemo.py::TestClass.test_three ✓ 100% ██████████
Results (0.14s):
4 passed
1 failed
- pytestDemo.py:37 TestClass.test_two