Search code examples
pytesttox

Tox InvocationError (exited with code 1) when running pytest


I am using Python 3.7.4, pytest 6.2.5, tox 3.24.4. Is it an expected behavior that pytest failure will cause tox command (wrap around the pytest) exited with code 1? Appreciate your insights.

Command as follows indicated in Jenkins console log:

foobar run-test: commands[0] | pytest test_foobar.py

Error below:

InvocationError for command /path/.tox/foobar/bin/pytest test_foobar.py (exited with code 1)

Here is the tox.ini file.

[tox]
envlist = foobar,xxx
skipsdist = true

[testenv]
basepython = python3.7
passenv = *

[testenv:foobar]
deps =
    -r requirements.txt
commands =
    pytest {posargs}

[testenv:xxx]
envdir = {toxworkdir}/foobar
deps = 
    {[testenv:foobar]deps}
commands =
    <something> {posargs}

Solution

  • As an addition to phds correct answer, that tox returns non-zero when one of the commands failed...

    If you really need a successful tox run although a command fails, you can prepend it with a dash.

    e.g.

    [testenv:foobar]
    deps =
        -r requirements.txt
    commands =
        - pytest {posargs}
    

    See https://tox.wiki/en/latest/config.html#conf-commands