question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pytestArgs: ["-n", "4"] not working for running tests in parallel with pytest-xdist

See original GitHub issue

Easy fix is to change docs to have “-n 4” instead of two args, but I don’t understand why “-n”, “4” is not working.

Environment data

  • VS Code version: 1.35.1
  • Extension version (available under the Extensions sidebar): 2019.7.21668-dev
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.1
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Relevant/affected Python packages and their versions: image

Expected behaviour

"python.testing.pytestArgs": ["-n 4"] and "python.testing.pytestArgs": ["-n", "4"] should have the same behaviour, shouldn’t it?

Actual behaviour

Having "python.testing.pytestArgs": ["-n", "4"] in settings.json throws an error:

pytest.py: error: argument -n/--numprocesses: invalid parse_numprocesses value: '.\\testing\\python\\approx.py'

and approx.py is the file from which I tried to execute the tests.

Steps to reproduce:

  1. Clone pytest repo
  2. Install dependencies if needed. Make sure pytest-xdist is installed
  3. Configure tests in the extension to use pytest framework and add "python.testing.pytestArgs": ["-n", "4"] to settings.json file
  4. Open the test explorer
  5. Discover tests works
  6. Run all tests works
  7. Run an individual test file and watch the “There was an error in running the tests” prompt appear

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

=========================== short test summary info ===========================
FAILED testing/logging/test_formatter.py::test_colored_short_level - Assertio...
===================== 1 failed, 2 passed in 0.98 seconds ======================
Error: Error: cannot open file:///c%3A/Users/luabud/pytest/c. Detail: Unable to read file (Error: File not found (c:\Users\luabud\pytest\c))
Test Discovery failed: 
TypeError: i.startsWith is not a function
Test Discovery failed: 
TypeError: i.startsWith is not a function
python C:\Users\luabud\.vscode\extensions\ms-python.python-2019.7.21668-dev\pythonFiles\testing_tools\run_adapter.py discover pytest -- -s --cache-clear -n 4
ERROR: usage: pytest.py [options] [file_or_dir] [file_or_dir] [...]
pytest.py: error: argument -n/--numprocesses: invalid parse_numprocesses value: '.\\testing\\python\\approx.py'

Error: TypeError: Cannot read property 'testsuite' of null
Test Discovery failed: 
TypeError: i.startsWith is not a function
Test Discovery failed: 
TypeError: i.startsWith is not a function
Test Discovery failed: 
TypeError: i.startsWith is not a function
python C:\Users\luabud\.vscode\extensions\ms-python.python-2019.7.21668-dev\pythonFiles\testing_tools\run_adapter.py discover pytest -- -s --cache-clear -n 4
ERROR: usage: pytest.py [options] [file_or_dir] [file_or_dir] [...]
pytest.py: error: argument -n/--numprocesses: invalid parse_numprocesses value: '.\\testing\\python\\integration.py'

Error: TypeError: Cannot read property 'testsuite' of null

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
luabudcommented, Jul 16, 2019

Validated

0reactions
ericsnowcurrentlycommented, Jun 26, 2019

I’m not sure we understand the problem yet. Passing the file last should work fine. If there’s a pytest bug then we a workaround is fine as long as we file an upstream bug and document the workaround.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pytest run tests parallel - python - Stack Overflow
I want to run all my pytest tests in parallel instead of sequentially. my current setup looks like: class Test1(OtherClass): @pytest. mark.
Read more >
Testing Python in Visual Studio Code
Support for running tests in parallel with pytest is available through the pytest-xdist package. To enable parallel testing: Open the integrated terminal and...
Read more >
test - Pants build
Benefit of Pants: runs each file in parallel. Each file gets run as a separate process, which gives you fine-grained caching and better...
Read more >
Pytest - Run Tests in Parallel - Tutorialspoint
Pytest - Run Tests in Parallel, By default, pytest runs tests in sequential order. In a real scenario, a test suite will have...
Read more >
Changelog — pytest documentation
This solves some issues with tests that involve pytest environment variables. ... properly when multiple instances of pytest are running in parallel.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found