当前位置:网站首页>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
边栏推荐
- V01 - XX, record a good life from the log
- C regards type as generic type T and uses it as generic type of method
- Today's sleep quality record 75 points
- Guys, how can CDC Oracle set the reading from the specified SCN number, or how to set the read-only full archive, not to read fast
- AI-理论-知识图谱1-基础
- B+树挑选索引(2)---mysql从入门到精通(二十三)
- Leetcode 1523. count odd numbers within the interval
- Shutter background graying effect, how transparency, gray mask
- Guys, please ask me, I have configured CDC to connect to Oracle according to the document, and I always run error reports and can't find the class validstione
- Hcip day 11 comparison (BGP configuration and release)
猜你喜欢
![[applet] why can't the onreachbottom event be triggered? (one second)](/img/da/3641040c63f6db4d227dcf2ff89919.png)
[applet] why can't the onreachbottom event be triggered? (one second)

被罚“带薪休假”一个月后,谷歌解雇了“爱”上 AI 的他

C regards type as generic type T and uses it as generic type of method

Niuke brush sql---2

postgresql官网下载出错

Hcip day 12 notes sorting (BGP Federation, routing rules)

最好的工程师,就是这样被你“逼”走的!

AI-理论-知识图谱1-基础
2022 employment season! Adobe helps creative industry workers break through the shackles of skills and return to the source of ability

Kubernetes apiserver current limiting strategy
随机推荐
V01 - XX, record a good life from the log
Redis realizes single sign on -- system framework construction (I)
B+树(5)myISAM简介 --mysql从入门到精通(十七)
0 basic programming resources (collect first ~ read slowly ~)
JSON format execution plan (6) - MySQL execution plan (52)
学习pinia 介绍-State-Getters-Actions-Plugins
【TypeScript】TypeScript常用类型(下篇)
StreamNative 团队文化:一家“透明”的公司
MySQL data directory (2) -- table data structure (XXV)
MySQL data directory (3) -- table data structure MyISAM (XXVI)
Solution: unable to load the file c:\users\user\appdata\roaming\npm\npx PS1, because running scripts is prohibited on this system.
Chat system based on webrtc and websocket
【花雕动手做】有趣好玩的音乐可视化系列小项目(12)---米管快速节奏灯
Leetcode 1523. count odd numbers within the interval
基于ASP.NET的某高校学院档案管理系统
Flutter textfield sets the height and automatically wraps lines, and the rounded border removes the underline
Flutter prevents scientific counting and removes mantissa invalid 0
【5GC】什么是5G切片?5G切片如何工作?
Extra(5)—mysql执行计划(五十一)
Router. Push(), router. Reply(), router. Go()