Why is pytest asking to specify –tx

Question:

After multiple successful tests, pytest is suddenly throwing this error:

$ pytest -vvv -x --internal --oclint -n -32
============================= test session starts ==============================
platform darwin -- Python 3.7.7, pytest-5.4.1, py-1.7.0, pluggy-0.13.1 -- /usr/local/opt/python/bin/python3.7
cachedir: .pytest_cache
rootdir: /Users/pre-commit-hooks/code/pre-commit-hooks, inifile: pytest.ini
plugins: xdist-1.31.0, forked-1.1.3
ERROR: MISSING test execution (tx) nodes: please specify --tx

This is my pytest.ini:

[pytest]
markers =
    oclint: marks tests as slow (deselect with '-m "not slow"')
    internal: marks tests as checking internal components. Use this if you are developing hooks

-n # is from pytest-xdist, which is an addon to pytest.
This was strange to me because pytest on a travis linux build was working just fine until the last iteration.

Question

Why is pytest asking me to add --tx for my tests?

Asked By: Ross Jacobs

||

Answers:

If you fat-finger a dash after the -n number like -n -32, pytest will complain about a missing --tx option. In other words the number after -n cannot be negative and what you want to use instead is -n 32.

--tx is normally used like so to invoke a Python2.7 subprocess:

pytest -d --tx popen//python=python2.7

More information about using --tx as part of pytest can be found in the pytest-xdist [docs on this flag](pytest -d –tx popen//python=python2.7).

Answered By: Ross Jacobs

I got this same pytest-xdist error but for a different reason. I had set --forked --dist=loadfile but did not specify --numprocesses. Setting that option fixed the error.

Answered By: crypdick

Just FYI: Similar error can happen if one specifies e.g. dist=loadfile without specifying -n 32.

Answered By: gebbissimo