-1

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}
CarolL
  • 59
  • 2
  • 8

2 Answers2

2

From the docs at https://tox.wiki/en/latest/index.html

Only if all environments ran successfully tox will return exit code 0 (success).

I.e., yes, it is an expected behavior that pytest failure will cause tox command exited with code 1.

phd
  • 82,685
  • 13
  • 120
  • 165
2

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

Jürgen Gmach
  • 5,366
  • 3
  • 20
  • 37