pytest实战
2020-09-26 本文已影响0人
info_gu







fixtrue用法:

-
fixtrue二种调用方式
image.png
- 第一种
import pytest
class TestFixtrue():
@pytest.fixture()
def login(self):
return "succuss"
def test_case01(self,login):
print(login)
print("testcase run")
- 第二种
@pytest.fixture(scope="function")
def start():
print("\n-----开始执行function------")
@pytest.mark.usefixtures("start")
def test_a():
print("------用例a执行------")
@pytest.mark.usefixtures("start")
class Test_aaa():
def test_01(self):
print("------用例01-------")
def test_02(self):
print("------用例02-------")
if __name__ == '__main__':
pytest.main(["-s","usefixtures.py"])


- conftest.py里面可以写公共的fixtrue供多个文件调用
fixtrue级别最好是session级别

-
参数化与数据驱动:
image.png

-
pytest常用插件
image.png



-
顺序
image.png


二种方法都可以行:





-
pytest高级用法(编写hook方法)
image.png







自定义命令:

配置conftest,可以通过不同的命令来区分test,dev来执行

-
pytest配置文件
image.png

