如何指定在 tox 中使用哪个位置参数?

发布于 2025-01-19 07:03:58 字数 437 浏览 4 评论 0原文

我有以下 tox.ini:

[tox]
envlist = py37-{lint, test}

[testenv:py37-{lint, test}]
envdir = {toxworkdir}/lint_and_test_env
deps = 
    pylint
    pytest
    pytest-xdist
commands =
    lint: pylint src {posargs}
    test: pytest tests {posargs}

我想并行运行两个环境,并为 pylint 指定 --jobs=4 ,为 pytest 指定 -n auto 。执行 tox -p -- --jobs=4 -n auto 失败,因为 pylint 无法识别 -n 参数,反之亦然。

有办法实现我的目标吗?

I have the following tox.ini:

[tox]
envlist = py37-{lint, test}

[testenv:py37-{lint, test}]
envdir = {toxworkdir}/lint_and_test_env
deps = 
    pylint
    pytest
    pytest-xdist
commands =
    lint: pylint src {posargs}
    test: pytest tests {posargs}

I want to run both environments in parallel and specify --jobs=4 for pylint and -n auto for pytest. Executing tox -p -- --jobs=4 -n auto fails because pylint does not recognize the -n argument and vice versa.

Is there a way to achieve my goal?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遮了一弯 2025-01-26 07:03:58

我看不出有什么办法可以做你想做的事。

也就是说,我强烈建议您拆分环境并使用一个用于测试,另一个用于 linting。

[tox]
envlist = py37, lint

[testenv]
deps =
    pytest
    pytest-xdist
commands =
    pytest tests {posargs}

[testenv:lint]
deps = pylint
commands = pylint src {posargs}

然后,您可以向命令传递不同的参数,或通过 tox 运行所有环境。

如果您未指定{posargs},您也可以设置默认值。

例如,

[testenv:lint]
deps = pylint
commands = pylint src {--jobs=4:posargs}

如果您想并行运行所有 tox env,您可以运行...

tox -p

PS:我是 tox 维护者之一,我为数百个开源项目做出了贡献项目,基本上 99% 使用单独的环境进行测试和 linting。

PPS:如果您想运行多个 linter,您应该查看预提交

I see no way to do what you want.

That said, I would strongly recommend that you split your environments and use one for testing and one for linting.

[tox]
envlist = py37, lint

[testenv]
deps =
    pytest
    pytest-xdist
commands =
    pytest tests {posargs}

[testenv:lint]
deps = pylint
commands = pylint src {posargs}

Then you can pass in different arguments to the commands, or run all envs via tox.

Also you could set defaults in case you do not specify {posargs}.

e.g.

[testenv:lint]
deps = pylint
commands = pylint src {--jobs=4:posargs}

If you want to run all tox envs in parallel you could run...

tox -p

P.S.: I am one of the tox maintainers, and I have contributed to hundreds of open source projects, and basically 99% use separate envs for testing and linting.

P.P.S.: If you want to run more than one linter, you should have a look at pre-commit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文