012、多个fixture的使用顺序
2021/7/19 6:07:46
本文主要是介绍012、多个fixture的使用顺序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、多个fixture的使用顺序
依据测试用例方法调用时的排序 执行
# -*- coding:utf-8 -*- # @Author: Sky # @Email: 2780619724@qq.com # @Time: 2021/7/18 23:47 import pytest @pytest.fixture() def first(): print('==========step1==========') @pytest.fixture() def second(): print('==========step2==========') @pytest.fixture() def three(): print('==========step3==========') def test_01(first, second, three): print('===========test_01=======') def test_02(second, first, three): print('===========test_01=======') def test_03(second, first): print('===========test_01=======')View Code
执行结果如下:
D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day06\ff>pytest -s =================================================================================== test session starts ==================================================================================== platform win32 -- Python 3.8.6, pytest-5.4.3, py-1.10.0, pluggy-0.13.1 rootdir: D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day06\ff plugins: allure-pytest-2.9.43, html-2.1.1, metadata-1.11.0 collected 3 items test_ff.py ==========step1========== ==========step2========== ==========step3========== ===========test_01======= .==========step2========== ==========step1========== ==========step3========== ===========test_01======= .==========step2========== ==========step1========== ===========test_01======= . ==================================================================================== 3 passed in 0.04s ===================================================================================== D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day06\ff>View Code
Fixture之间也可以互相调用
# -*- coding:utf-8 -*- # @Author: Sky # @Email: 2780619724@qq.com # @Time: 2021/7/18 23:47 import pytest @pytest.fixture() def first(): print('==========step1==========') @pytest.fixture() def second(first): print('==========step2==========') @pytest.fixture() def three(second): print('==========step3==========') def test_01(three): print('===========test_01=======')View Code
执行结果如下:
D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day06\ff>pytest -s =================================================================================== test session starts ==================================================================================== platform win32 -- Python 3.8.6, pytest-5.4.3, py-1.10.0, pluggy-0.13.1 rootdir: D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day06\ff plugins: allure-pytest-2.9.43, html-2.1.1, metadata-1.11.0 collected 1 item test_ff.py ==========step1========== ==========step2========== ==========step3========== ===========test_01======= . ==================================================================================== 1 passed in 0.03s ===================================================================================== D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day06\ff>View Code
示例2:
# -*- coding:utf-8 -*- # @Author: Sky # @Email: 2780619724@qq.com # @Time: 2021/7/18 23:47 import pytest @pytest.fixture() def username(): print('==========获取用户名==========') name = 'sky' return name @pytest.fixture() def passwd(username): print('==========获取密码==========') pwd = '123456' return pwd @pytest.fixture() def login(username, passwd): print('==========登录==========') name = username pwd = passwd return 'success' def test_01(login): print('===========测试登录=======') assert login == 'success'View Code
执行结果如下:
==================================================================================== 1 passed in 0.03s ===================================================================================== D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day06\ff>pytest -s =================================================================================== test session starts ==================================================================================== platform win32 -- Python 3.8.6, pytest-5.4.3, py-1.10.0, pluggy-0.13.1 rootdir: D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day06\ff plugins: allure-pytest-2.9.43, html-2.1.1, metadata-1.11.0 collected 1 item test_ff.py ==========获取用户名========== ==========获取密码========== ==========登录========== ===========测试登录======= . ==================================================================================== 1 passed in 0.04s ===================================================================================== D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day06\ff>View Code
这篇关于012、多个fixture的使用顺序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-23线下车企门店如何实现线上线下融合?
- 2024-12-23鸿蒙Next ArkTS编程规范总结
- 2024-12-23物流团队冬至高效运转,哪款办公软件可助力风险评估?
- 2024-12-23优化库存,提升效率:医药企业如何借助看板软件实现仓库智能化
- 2024-12-23项目管理零负担!轻量化看板工具如何助力团队协作
- 2024-12-23电商活动复盘,为何是团队成长的核心环节?
- 2024-12-23鸿蒙Next ArkTS高性能编程实战
- 2024-12-23数据驱动:电商复盘从基础到进阶!
- 2024-12-23从数据到客户:跨境电商如何通过销售跟踪工具提升营销精准度?
- 2024-12-23汽车4S店运营效率提升的核心工具