为 tox 设置 pytest arg 但不是直接 pytest
set pytest arg for tox but not direct pytest
默认情况下,我会使用一些参数 (-n 2
) tox to 运行 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
中添加标志,正如您已经在做的那样;另一种是使用环境变量:
You can set a PYTEST_ADDOPTS
environment variable to add command line options while the environment is in use:
export PYTEST_ADDOPTS="-v"
因此,如果您在 tox.ini
的 [tox]
块中添加参数;例如:
[tox]
setenv=
PYTEST_ADDOPTS="-n 2"
并且不要在 [pytest]
块中设置标志,您应该只在 运行 py.test 使用 tox 时看到应用的参数。
有点不雅,但我认为它可以解决问题。
(FWIW,我已经尝试在 tox.ini for hypothesis-python 中进行更改,并且它具有预期的效果。)
默认情况下,我会使用一些参数 (-n 2
) tox to 运行 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
中添加标志,正如您已经在做的那样;另一种是使用环境变量:
You can set a
PYTEST_ADDOPTS
environment variable to add command line options while the environment is in use:export PYTEST_ADDOPTS="-v"
因此,如果您在 tox.ini
的 [tox]
块中添加参数;例如:
[tox]
setenv=
PYTEST_ADDOPTS="-n 2"
并且不要在 [pytest]
块中设置标志,您应该只在 运行 py.test 使用 tox 时看到应用的参数。
有点不雅,但我认为它可以解决问题。
(FWIW,我已经尝试在 tox.ini for hypothesis-python 中进行更改,并且它具有预期的效果。)