当前位置:网站首页>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
边栏推荐
- Kubelet CRI container runtime
- 牛客刷SQL---2
- 最好的工程师,就是这样被你“逼”走的!
- 基于C#开放式TCP通信建立与西门子PLC的socket通信示例
- Kubernetes flannel: host-gw mode
- Mysql数据目录(2)---表数据结构(二十五)
- 基于Locust框架进行文件上传下载性能测试
- Display inline+calc realizes left, middle and right layout, and the middle is adaptive
- 父组件访问子组件的方法或参数 (子组件暴漏出方法defineExpose)
- 【花雕动手做】有趣好玩的音乐可视化系列小项目(13)---有机棒立柱灯
猜你喜欢

Kubernetes ---- life cycle introduction of PV and PVC

8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
![[upper computer tutorial] Application of integrated stepping motor and Delta PLC (as228t) under CANopen communication](/img/d4/c677de31f73a0e0a4b8b10b91e984a.png)
[upper computer tutorial] Application of integrated stepping motor and Delta PLC (as228t) under CANopen communication

Visual stdio(VS)中的(int argc、char** argv)命令行参数

基于C#开放式TCP通信建立与西门子PLC的socket通信示例
![[typescript] typescript common types (Part 2)](/img/6b/2ac07f16af044bdfb719753ae241cc.png)
[typescript] typescript common types (Part 2)

RMII, smii, gmii, rgmii interfaces of Ethernet Driver

Kubernetes APIServer 限流策略

Version of NDK matched the requested version 21.0.6113669. versions available locally: 2

0基础编程资源大全(先收藏~慢慢看~)
随机推荐
Kubelet CRI 容器运行时
基于WebRTC和WebSocket实现的聊天系统
RMII, smii, gmii, rgmii interfaces of Ethernet Driver
The child component triggers the defineemits of the parent component: the child component passes values to the parent component
高通再次「押宝」中科创达,挑战智能驾驶软硬件全栈方案
JSON format execution plan (6) - MySQL execution plan (52)
Px2rem loader converts PX into REM and adapts to mobile vant UI and other frameworks
C#把Type当做泛型T,来作为方法的泛型进行使用
HCIP第十一天比较(BGP的配置、发布)
File upload and download performance test based on the locust framework
Streamnational team culture: a "transparent" company
Outline design specification
panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)
jvm:类加载子系统干什么的?由什么组成?需要记住哪些八股文?
从其他文件触发pytest.main()注意事项
Example of establishing socket communication with Siemens PLC based on C # open TCP communication
postgresql官网下载出错
V00 - do whatever you want when you are old
Bitwise and how to write SQL
Some practical operations of vector