Python tox deps with patterned commands

Python tox deps with patterned commands

我正在使用 tox 进行测试。目前我的 tox.ini 定义了几个命令:

commands =
    unit-a: py.test --cov mypackage mypackage/tests/unit/a []
    unit-b: py.test --cov mypackage mypackage/tests/unit/b []
    func: python -m behave -n "{env:SCENARIO}"

它还定义了每个命令的依赖关系:

deps =
    unit-a: mock
    unit-a: pytest==3.9.3
    unit-a: pytest-cov
    unit-a: pytest-sugar
    unit-b: mock
    unit-b: pytest==3.9.3
    unit-b: pytest-cov
    unit-b: pytest-sugar
    func: behave

这对我来说既笨重又多余。有没有办法使用命令模式来指定 deps?例如,

deps =
    unit-*: mock
    unit-*: pytest==3.9.3
    unit-*: pytest-cov
    unit-*: pytest-sugar
    func: behave

这是我在尝试时遇到的错误:

ERROR: invocation failed (exit code 1), logfile: /app/.tox/py3-unit-a/log/py3-unit-a.log
ERROR: actionid: py3-unit-a
msg: getenv
cmdargs: "/app/.tox/py3-unit-a/bin/pip install --progress-bar off --index-url=https://pypi.org/simple 'unit-*: mock' 'unit-*: pytest==3.9.3' 'unit-*: pytest-cov' 'unit-*: pytest-sugar'"

Invalid requirement: 'unit-*: mock'

你可以简单地做:

deps =
    unit: mock pytest==3.9.3 pytest-cov pytest-sugar
    func: behave

带有 unit: 的第一行有效,因为 tox splits factors by -.

你也可以试试否定:

deps =
    !func: mock pytest==3.9.3 pytest-cov pytest-sugar
    func: behave