gpt4 book ai didi

pytest - 为 tox 设置 pytest arg 但不是直接 pytest

转载 作者:行者123 更新时间:2023-12-04 16:45:32 30 4
gpt4 key购买 nike

我会默认使用一些参数( -n 2 )运行 pytest 但如果我只输入 pytest ... ,我不希望默认使用该参数直接运行pytest。这可能吗?

如果我包括这个:

[pytest]
addopts=-n 2

tox.ini ,然后 tox使用选项(根据需要),但也使 pytest如果我只运行 pytest ...,请使用该选项不是通过毒素(不需要)。

我尝试添加 pytest.ini , 但随后是 tox.ini 中的默认值根本不使用(无论是否通过 tox 运行)。

有什么帮助吗?

最佳答案

py.test 文档描述了 several ways to change configuration .一种是在tox.ini中添加flags ,正如你已经在做的那样;另一种是使用环境变量:

You can set a PYTEST_ADDOPTS environment variable to add command line options while the environment is in use:

export PYTEST_ADDOPTS="-v"


因此,如果您在 [tox] 中添加参数屏蔽您的 tox.ini ;例如:
[tox]
setenv=
PYTEST_ADDOPTS="-n 2"

并且不要在 [pytest] 中设置标志块,您应该只看到在使用 tox 运行 py.test 时应用的那些参数。

这有点不优雅,但我认为它可以解决问题。

(和 FWIW,我已经尝试在 tox.ini for hypothesis-python 中进行更改,并且它具有预期的效果。)

关于pytest - 为 tox 设置 pytest arg 但不是直接 pytest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48856608/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com