Search code examples
pytestteamcitytox

How can I get a green TeamCity build with muted red pytest run from tox?


I have the following tox.ini file:

[tox]
envlist = py310, flake8
isolated_build = True

[testenv]
skip_install = True
deps = -rtest_requirements.txt
passenv = *

commands =
    pytest {posargs} --teamcity

[testenv:flake8]
deps = flake8
skip_install = True
commands = flake8 tests/

On teamcity, I run my python test through tox from within a script build step where I call the following shell script

#! /bin/sh

python -m tox .

Now, there is one red test that I want to mute. When I mute it, however, teamcity makes my build red even though it marked my test as muted, like so:

teamcity error

The problem is well-known, since 11 years, as reported here.

How can I modify my command in my tox.ini file to make my build green again? I don't want to mark my python test with the skip tag. I don't want to change the tox command from

commands =
    pytest {posargs} --teamcity

to

commands =
   - pytest {posargs} --teamcity

because that will just ignore any error that might happen during the pytest run (like "Internal error happened while executing tests", or "No tests were collected" for example).

Ideally, I would like to call

commands =
   pytest {posargs} --teamcity || [ $? = 1 ]

but apparently tox does not understand the symbol ||.

What can I do?


Solution

  • You can call a custom shell script in your commands section, and there you can do whatever you want, including using ||.

    e.g.

    commands = my_custom_script.sh