How to fix "pytest: error: unrecognized arguments: -n"
Asked Answered
I

3

18

Hi I am trying to run my tests parallely(pytest-xdist) on the azure pipelines. Till now the tests were running perfectly fine. Suddenly the pytest is throwing a weird error saying "unrecognized argument".

The file name : integration_test.py Command used : pytest -n 5 --tb=short integration_test.py -v -s --> to run 5 tests parallely Total number of tests : 57 Versions : pytest==6.2.5 pytest-xdist==2.3.0 Even tried with the latest versions of these 2 modules.

Error : ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...] pytest: error: unrecognized arguments: -n integration_test.py

How can I overcome this error?

Inerrant answered 9/1, 2022 at 4:22 Comment(4)
You haven‘t installed pytest-xdist which adds the -n argument.Dateline
I have installed the pytest-xdist module.Inerrant
Still facing the issueInerrant
Then you probably haven't installed it for the right interpreter. Run pytest -v --collect-only, is xdist listed in plugins? Best add the output to the question.Dateline
I
13

This error is what you encountered:

Error : ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...] pytest: error: unrecognized arguments: -n integration_test.py  
  initfile: None
  rootdir: C:\test

enter image description here

As hoefling mentioned, the solution is to install the pytest-xdist:

pip install pytest-xdist

Impeach answered 10/1, 2022 at 2:26 Comment(0)
F
0

On MacOS just running pytest might be ran by a different Python's version than you thought.

$ pytest
============================================================================== test session starts ===============================================================================
platform darwin -- Python 3.9.12, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
rootdir: [REDACTED]
plugins: anyio-3.5.0, cov-3.0.0

While

$ python3 -m pytest
============================================================================== test session starts ===============================================================================
platform darwin -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0
rootdir: [REDACTED]
plugins: xdist-2.5.0, forked-1.4.0, pylama-8.4.1

Be careful, and launch it as a module :)

Faze answered 22/8, 2022 at 16:47 Comment(0)
S
0

I encountered the same error while adding my own argument to pytest. The problem was that my conftest.py was not on /tests level in project, but in /tests/suites. Maybe it will help someone with similar problem.

Sexdecillion answered 1/8, 2024 at 15:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.