pytest入门三:setup、teardown
https://zhuanlan.zhihu.com/p/623447031
function对应类外的函数,每个函数调用一次
import pytest
def setup_module():
print('开始 module')
def teardown_module():
print('结束 module')
def setup_function():
print('开始 function')
def teardown_function():
print('结束 function')
def test_one():
print('这是one')
class TestDemo:
def setup_class(self):
print('开始 class')
def teardown_class(self):
print('结束 class')
def setup_method(self):
print('开始 method')
def teardown_method(self):
print('结束 method')
def setup(self):
print('开始 setup')
def teardown(self):
print('结束 setup')
def test_two(self):
print('这是two')
assert 1 == 1
def test_three(self):
print('这是three')
assert 1 > 0
if __name__ == "__main__":
pytest.main(['-v', '-s','test.py'])