如何在tox中只运行一个测试?

int*_*_ua 13 python tox

我正在尝试为项目编写一个新测试,我只想在tox中测试一个测试.我已经完全确定其他测试都没问题,我不需要每次都运行它们.我发现的唯一建议不起作用

ERROR: InvocationError: could not find executable 
Run Code Online (Sandbox Code Playgroud)

Mar*_*oma 24

jason meridth撰写:

$ tox -e py35 -- project/tests/test_file.py::TestClassName::test_method
Run Code Online (Sandbox Code Playgroud)

beluga.me在评论中提到了细粒度:如果你有一个tox.ini文件,你可能需要{posargs}在tox.ini中添加到pytest:

[tox]
envlist = py35

[testenv]
deps =
    pytest
    pytest-cov
    pytest-pep8
commands =
    pip install -e .
    pytest {posargs}
Run Code Online (Sandbox Code Playgroud)

使用unittest运行一个测试

python3 -m unittest -q test_file.TestClassName
Run Code Online (Sandbox Code Playgroud)


Yae*_*ael 7

运行此命令:

tox -epy27 -- test_name
Run Code Online (Sandbox Code Playgroud)

了解更多信息

  • 发现我的问题,应该仔细查看 tox.ini,如果 `commands =` 没有 `{posargs}`,它将忽略您添加到命令中的任何内容。 (24认同)