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函数的测试用例才会生效

相关推荐
2601_962387823 天前
web自动化测试实战教程【selenium/unittest/pytest】【共193课
selenium·pytest·devops·web自动化测试·unittest
weixin_440730503 天前
使用pytest中方法控制执行步骤(test_begin.py、test_end.py,@pytest.mark.run(order=1))
开发语言·python·pytest
2601_962297253 天前
Python、Pytest、Allure、Selenium和Jenkins实现自动化测试集成实例
python·selenium·jenkins·pytest·allure
2601_962077604 天前
从零搭建Python接口自动化测试框架:pytest+requests实战指南
python·pytest·接口自动化·requests·框架搭建
weixin_440730504 天前
pytest结合allure生成html测试报告(step、story、severity、screenshot)
前端·html·pytest·allure报告
拜托多多指教4 天前
【Pytest框架学习】分层架构
python·pytest
2601_962299884 天前
python脚本如何单元测试
python·单元测试·pytest·unittest·mock对象
Tizzy JJ5 天前
Python + pytest 接口自动化测试框架实战:从零搭建企业级项目骨架
开发语言·python·pytest
Tizzy JJ5 天前
接口自动化测试实战:如何围绕真实业务场景设计高质量用例
python·自动化·pytest
测试老哥6 天前
Pytest 之assert断言的使用
自动化测试·软件测试·python·测试工具·测试用例·pytest·接口测试