当前位置:网站首页>Precautions for triggering pytest.main() from other files
Precautions for triggering pytest.main() from other files
2022-07-26 13:16:00 【russle】
demand : When starting the test , Not directly pytest xxx, But there is a separate py File where call pytest.main(), In this way, you can perform some required operations at the beginning , Of course, these operations are placed in pyest Various setup You can also do so. , However, there is a need to read some environment changes, but the external finally decided not to pass through environment variables but in the form of parameters for various reasons ( As for why we can't pass through the environment, it's not within the scope of this article , Nor is it the focus of this article ).
If you start pytest The code for is as follows ( A simple example , Don't worry about code style to be brief , This is just to illustrate the problem )
import pytest
import sys
if __name__ == '__main__':
print("env arg")
print(sys.argv)
print(sys.argv[1])
pytest.main()
Input parameters
python pytest_main.py -envType=dev
env arg
['pytest_main.py', '-envType=dev']
-envType=dev
ERROR: usage: pytest_main.py [options] [file_or_dir] [file_or_dir] [...]
pytest_main.py: error: unrecognized arguments: -envType=dev
inifile: /Users/xxx/PycharmProjects/celldbtest/pytest.ini
rootdir: /Users/xxx/PycharmProjects/celldbtest
You can find here -envType=dev It was taken as pytest The parameters of , And perform python pytest_main.py -c pytest.ini Yes. .
terms of settlement :
Because we actually tested the relevant configuration parameters in pytest.ini in , So we just need pytest.main() Specifies the file to read , He ignores the rest of the parameters
import pytest
import sys
if __name__ == '__main__':
print("env arg")
print(sys.argv)
print(sys.argv[1])
pytest.main(['-c', 'pytest.ini'])
At this time, the output of additional parameters at startup is pytest.main([‘-c’, ‘pytest.ini’]) Before processing , And these parameters will not be passed to pytest.main
python pytest_main.py -envType=dev -arg=val2
边栏推荐
- JSON format execution plan (6) - MySQL execution plan (52)
- 12-GuliMall 后台管理中商品系统的品牌管理
- Kubelet CRI 容器运行时
- Food safety | what food can be heated in a microwave oven? You should know these potential safety hazards
- 同花顺开的账户安全吗?
- Today in history: IBM obtained the first patent; Verizon acquires Yahoo; Amazon releases fire phone
- 基于Locust框架进行文件上传下载性能测试
- LeetCode 1523. 在区间范围内统计奇数数目
- 12 brand management of commodity system in gulimall background management
- 深度学习3D人体姿态估计国内外研究现状及痛点
猜你喜欢

Panorama of volcanic engine cloud growth plan: 30 + plans come out together, and military development advantage areas

Kubernetes APIServer 限流策略

高通再次「押宝」中科创达,挑战智能驾驶软硬件全栈方案

Kubernetes flannel: host-gw mode

【花雕动手做】有趣好玩的音乐可视化系列小项目(13)---有机棒立柱灯

3D modeling and rendering based on B é zier curve
![[typescript] typescript common types (Part 1)](/img/80/5c8c51b92d3a9d76f38beba7be0aa6.png)
[typescript] typescript common types (Part 1)

A college archives management system based on asp.net

(int argc, char** argv) command line parameters in visual stdio (VS)

Learn about Pinia state getters actions plugins
随机推荐
Remote IP debugger (Practical dry goods)
【5GC】什么是5G切片?5G切片如何工作?
【TypeScript】TypeScript常用类型(下篇)
B+树(3)聚簇索引,二级索引 --mysql从入门到精通(十五)
Kubernetes apiserver current limiting strategy
Leetcode 263. ugly number
关于自动重复调用接口的一种实现方式-反射
Hcip day 12 notes sorting (BGP Federation, routing rules)
Mysql数据目录(2)---表数据结构(二十五)
Food safety | can you eat any fruit?
历史上的今天:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone...
V01 - XX, record a good life from the log
最好的工程师,就是这样被你“逼”走的!
【上位机教程】CANopen通信下一体化步进电机与台达PLC(AS228T)的应用
【5G】5G中的CU和DU是什么?
基于ASP.NET的某高校学院档案管理系统
Display inline+calc realizes left, middle and right layout, and the middle is adaptive
B+树索引使用(9)分组、回表、覆盖索引(二十一)
Qualcomm once again "bet" on Zhongke Chuangda to challenge the full stack solution of intelligent driving software and hardware
Kubernetes APIServer 限流策略