当前位置:网站首页>Pytest multi file execution sequence control
Pytest multi file execution sequence control
2022-04-21 12:46:00 【FatPuffer】
1. only one py file
- 1. Use
pytestDo interface tests , If you testcaseOnly exists in a single.pyfile , So the testcaseBy default, it is executed from top to bottom , If usedpytest-orderplug-in unit
2. If there are multiple py file
-
1. Use
pytestDo interface tests , If you testcaseExist in multiple.pyIn file , The default is based on the file nameasciiCode sequence execution , After entering the document , By default, each unit test interface is executed from top to bottom .test_user.py # User correlation class TestUser: def test_user_create: def test_user_login: def test_user_delete test_order.py # Order related class TestOrder: def test_order_create: def test_order_list: def test_order_delete test_stock.py # Inventory related class TestStock: def test_stock_add: def test_stock_list: def test_stock_reduce1. By file name ascii Sort :test_order > test_stock > test_user
2.test_order_create > test_order_list > test_order_delete > test_stock_add > test_stock_list > …
-
2. If single
.pyIn the test filepytest-orderplug-in unit , Then... Is added to the fileorderTest cases will be executed first , Those not added will follow1Sequential execution , In this way, the sequence of unit tests will cross execute in multiple files .( So single.pyThe file is in usepytest-orderIn the case of plug-ins , Suggest that eachcaseTake them allorder=x, AndxDon't be the same )test_user.py # User correlation class TestUser: @pytest.mark.run(order=1) def test_user_create: def test_user_login: @pytest.mark.run(order=2) def test_user_delete test_order.py # Order related class TestOrder: def test_order_create: def test_order_list: def test_order_delete test_stock.py # Inventory related class TestStock: def test_stock_add: def test_stock_list: def test_stock_reduce1. because test_user In the document case Used pytest-order plug-in unit , So the priority implementation uses order Sort of case
2.test_user_create > test_user_delete> test_order_create> … > test_stock_add > … > test_user_delete
-
3. If more than one
.pyThe file usespytest-orderplug-in unit , If eachorderThe specified order does not conflict , Just followorderExecute in the specified order , If there is a conflict , That will appear in multiple.pyCross execution in the file ,ProbablyNot in line with our expectations .test_user.py # User correlation class TestUser: @pytest.mark.run(order=1) def test_user_create: def test_user_login: @pytest.mark.run(order=2) def test_user_delete test_order.py # Order related class TestOrder: def test_order_create: def test_order_list: def test_order_delete test_stock.py # Inventory related class TestStock: @pytest.mark.run(order=1) def test_stock_add: @pytest.mark.run(order=2) def test_stock_list: def test_stock_reduce1.test_stock and test_user There is order Conflict , So according to the file name
asciiOrder2.test_stock_add > test_user_create > test_stock_list > test_user_delete > order relevant > test_stock_reduce > test_user_login
4. Multiple py The file is modified according to the file name ascii Code sorting method
-
demand : Don't go back and forth in multiple files
case, Ensure that the sequence of test cases is :User module --> Order module --> Inventory module -
Mode one : By changing the file name , Make the file name
asciiSort code , Test with uscaseThe execution sequence is consistent , Make surecaseThere is nopytest-orderplug-in unittest_1_user.py # User correlation class TestUser: def test_user_create: def test_user_login: def test_user_delete test_2_order.py # Order related class TestOrder: def test_order_create: def test_order_list: def test_order_delete test_3_stock.py # Inventory related class TestStock: def test_stock_add: def test_stock_list: def test_stock_reduceBut usually , We
.pyFiles are named according to modules , So we can achieve the expected execution order by modifying the file name , Not very friendly -
Mode two : If you use
pytest-orderPlug in to control , It must be ensured that each document isorderValue cannot be repeated , After a.pyfileorderThe minimum value must be greater than the previous.pyMaximum file size , This ensures that the file execution orderIn this way, after adding test cases , You may need to modify a lot
orderThe ordertest_user.py # User correlation class TestUser: @pytest.mark.run(order=1) def test_user_create: @pytest.mark.run(order=3) def test_user_login: @pytest.mark.run(order=2) def test_user_delete test_order.py # Order related class TestOrder: @pytest.mark.run(order=4) def test_order_create: @pytest.mark.run(order=5) def test_order_list: @pytest.mark.run(order=6) def test_order_delete test_stock.py # Inventory related class TestStock: @pytest.mark.run(order=7) def test_stock_add: @pytest.mark.run(order=8) def test_stock_list: @pytest.mark.run(order=9) def test_stock_reduce -
Mode three : adopt
pytestThe hook method providedpytest_collection_modifyitems, YescaseThe execution sequence is modified# conftest.py def pytest_collection_modifyitems(config, items) # Expect the use case sequence to follow .py File execution appoint_classes = { "TestUser": [], "TestOrder": [], "TestStock": []} for item in items: for cls_name in appoint_classes: if item.parent.name == cls_name: appoint_classes[cls_name].append(item) items.clear() for cases in appoint_classes.values(): items.extend(cases)Users only need to add their new test modules
classAdd to... In the expected orderappoint_classesThen you can , Simple and flexible
版权声明
本文为[FatPuffer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211237330340.html
边栏推荐
- 弹性架构内容和成本探讨-数字化架构设计(3)
- 主从复制--03---同步数据一致性问题
- 实例:用C#.NET手把手教你做微信公众号开发(7)--普通消息处理之位置消息
- LLVM之父ChrisLattner:编译器的黄金时代
- 第四章 SQL查询之-层次化查询
- How to achieve centralized management, flexible and efficient CI / CD online seminar highlights sharing
- [MySQL] extract and query JSON type field data
- 机器学习-Sklearn-13(回归类大家族-下——非线性问题:多项式回归(多项式变换后形成新特征矩阵))
- CVPR 2022 oral | Hong Kong Chinese open source posec3d: skeleton motion recognition framework based on 3d-cnn
- Title record of TIANTI competition (II)
猜你喜欢

pycharm 跳转到指定行

Vggnet neural network based on pytorch for flower recognition

Aaai2022 | unbiased temporal knowledge reasoning based on probabilistic soft logic

win11的WiFi按钮不见了无法联网

机器学习-Sklearn-13(回归类大家族-下——非线性问题:多项式回归(多项式变换后形成新特征矩阵))

2020年4面美团(多线程+redis

Three. JS learning project -- 3D data visualization of anti US aggression and aid Korea

Three.js学习项目--3D抗美援朝数据可视化

Bevsegformer: a Bev semantic segmentation method from any camera

2022年监理工程师考试质量、投资、进度控制练习题及答案
随机推荐
R语言实现决策回归树的包rpart
Reverse crawler 30 verification code of a fourth generation slider
[SQL] sql19 finds the last of all employees_ Name and first_ Name and corresponding Dept_ name
爱可可AI前沿推介 (4.21)
最长上升子序列(二)(贪心+二分)
风丘科技为您提供10M以太网解决方案
WordPress plugin IQ block country 1.2.13 delete any file through zip slip
Go语言 反射
Insert multiple pieces of data into the database in idea
【贪玩巴斯】带你拿雅思Task1 小作文 7+ —— Dynamic+Static图表 & Mixed多图(Table/pie chart/line graph/bar chart)2022-4-18
2022年初级会计职称考试经济法基础练习题及答案
Three.js学习项目--3D抗美援朝数据可视化
Web--用户注册界面
Who does the team listen to
AGP Transform API 被废弃意味着什么?
字段行相同则合并在另外一个字段sql 语句?
构建QML应用程序
There is no market for virtual currency. Why can there be no small temptation for some people?
Jsapi payment is missing appid
只出现一次的数字 II(哈希、位操作、逻辑电路、有限状态自动机)