0

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?

Ross Jacobs
  • 2,962
  • 1
  • 17
  • 27
  • I am adding this question/answer because I solved it for myself and wanted to share. No further answers are necessary (but if there's more context to the underlying reason that it's parsed this way, by all means - knowledge is power). – Ross Jacobs Mar 26 '20 at 02:32

3 Answers3

1

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).

Ross Jacobs
  • 2,962
  • 1
  • 17
  • 27
  • How does `-n` interact with `--tx`? Are they completely independent options? Wouldn't `-n 8` be the equivalent of `--tx 8*popen`? – CMCDragonkai Sep 02 '20 at 04:40
  • Reading the [documentation](https://docs.pytest.org/en/3.0.1/xdist.html), `-n 8` will run pytest over 8 CPUs whereas `--tx 8*popen` will open 8 subprocesses, which could all be on one CPU. – Ross Jacobs Sep 02 '20 at 05:30
  • Running pytest over 8 cpus due to Python GIL would mean that pytest has to launch 8 subprocesses. And also opening 8 subprocesses which could be 1 CPU. Sure but that's why you have pre-emptive CPU schedulers which will schedule the 8 subprocesses over cores. – CMCDragonkai Sep 03 '20 at 05:36
  • My answer concerns fat fingering a dash. You are polluting my answer with irrelevant discussion. Please ask your own question. – Ross Jacobs Sep 03 '20 at 06:06
1

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.

crypdick
  • 16,152
  • 7
  • 51
  • 74
0

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

gebbissimo
  • 2,137
  • 2
  • 25
  • 35