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

相关推荐
St_rive3 天前
Pytest skip&&skipif跳过⽤例
运维·服务器·pytest
努力搬砖的咸鱼5 天前
AI Agent测试全景图:它到底改变了什么
人工智能·python·ai·集成测试·pytest·agent·ai编程
X1A0RAN7 天前
自动化流水线提效·微观篇:pytest 执行顺序优化
自动化·pytest
久久学姐14 天前
Python+Playwright+Pytest+BDD,用FSM打造高效测试框架
python·pytest·bdd·playwright·fsm
小白上线*^_^*15 天前
Pytest 自动化测试框架速通指南(二)
软件测试·pytest·python测试框架·ai测试基础
Logintern0916 天前
pytest的AST 断言重写
pytest
Tinyfacture16 天前
接口自动化之添加商品(pytest)
python·测试工具·自动化·pytest
ji_shuke18 天前
从零深入:基于 Playwright + Pytest + Allure 的企业级 Web 端到端自动化测试框架实战
前端·自动化测试·docker·jenkins·pytest·allure·playwright
祉猷并茂,雯华若锦20 天前
Selenium+Pytest自动化测试框架实战
selenium·测试工具·pytest