pytest-fixture固件的使用

**fixture 固件:pytest自动化中用于前后置,功能强大,可替代setup,teardown,setup_class,teardown_class

装饰器:
@pytest.fixture(scope="作用域", params="参数化", autouse="自动执行", ids="参数别名", name="别名"**

下面是fixture的两种用法:

1.fixture固件的自动调用

1)@pytest.fixture(scope='class',params='name1','name2',autouse=True)

def login(request):

print("用户登录")

yield reqyest.param

print("退出登录")

2)类中的每个用例都会自动调用login

2.fixture固件的手动调用

1)@pytest.fixture(scope='function',autouse=False)

def login():

print("用户登录")

yield #启用后置

print("退出登录")

2)测试用例中手动调用

def test_001(self, login):

只有指定的如上述调用了fixture函数的测试用例才会生效

相关推荐
糖果店的幽灵14 天前
软件测试接口测试从入门到精通:Python接口自动化 - pytest测试框架
软件测试·python·功能测试·自动化·pytest·接口测试
2601_9618752414 天前
花生十三资料1200题|题库|刷题
conda·pytest·pillow·pip·web3.py·ipython·gunicorn
某人辛木15 天前
Web自动化测试
前端·python·pycharm·pytest
淡漠的蓝精灵17 天前
pytest-xdist:把 pytest 测试分发到多核 CPU 执行
其他·pytest
弹简特18 天前
【接口自动化】03-YAML详解及Parametrize数据驱动
自动化·pytest
007张三丰20 天前
软件测试专栏(11/20):测试框架开发:pytest深度解析与插件体系
运维·服务器·自动化测试·pytest·测试框架
我的xiaodoujiao20 天前
API 接口自动化测试详细图文教程学习系列25--继续处理testCase中的数据
python·学习·测试工具·pytest
xiaobai17821 天前
pytest+playwright实现UI自动化(4)-上夹具fixture
ui·自动化·pytest·playwright
弹简特21 天前
【接口自动化】02-Pytest固件fixture核心机制与Allure企业级报告实战
自动化·pytest·测试