1.下载模块:pytest,allure-pytest(生成测试报告用)
2.下载allure插件:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
将插件bin目录添加到环境变量
3.JAVA环境配置
1.类测试用例:以首字母大写的Test开头,类方法以test开头
2.函数测试用例:以test开头
点击绿色按钮执行用例
需要将pycharm运行框架改为pytest,绿色箭头就会出现
(files–>settings–>tools–>python integrated tools–>default Test runner–>pytest)
def setup_module(): #模块setup固件
print('in setup_module')
def teardown_module():#模块teardown固件
print('in teardown module')
def setup_function():#模块函数setup固件
print('in set_up_function')
def teardown_function():#模块teardown固件
print('in teardown_function')
@pytest.fixture
def teardown():
print('in pytest_teardown')
a = ['asd','asd']
return a
def test5(setup,teardown):
print('teardown = ',teardown)
print('in test5:------')
@pytest.fixture
def teardown(request): #只能是request参数
def teardown1():
print('in teardown1')
def teardown2():
print('in teardown2')
#注册清理函数
request.addfinalizer(teardown2)
request.addfinalizer(teardown1)
def test1(teardown):
print('in test1')
@pytest.fixture
def teardown(request): #只能是request参数
print('in fixture')
yield 'return_vaue'
print('in teardown')
def test1(teardown):
print(teardown)
print('in test1')