Vscode-python: Error when running tests: Cannot read property 'testsuites' of null

Created on 25 Sep 2020  Â·  5Comments  Â·  Source: microsoft/vscode-python

Environment data

  • VS Code version: 1.49.2 (user setup)
  • Extension version (available under the Extensions sidebar): v2020.9.111407
  • OS and version: Windows_NT x64 10.0.18363
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.9 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: pytest==6.0.2
  • Value of the python.languageServer setting: Pylance

Expected behaviour

Test are run after >Python: Run All Tests command

Actual behaviour

There is an error when running the tests.
Command 'Python: Run All Tests' resulted in an error (Cannot read property 'testsuites' of null)
Output: c:UsersVaust XIIIAppDataLocalProgramsPythonPython37python.exe: can't open file '"c:/Users/Vaust XIII/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py"': [Errno 22] Invalid argument
Error: TypeError: Cannot read property 'testsuites' of null

Steps to reproduce:

Test have been running fine, then I added a new one and started getting this error. I tried deleting the new test, but it didn't help, the error is still there

hello.py

def hello():
    return "Hello"

hello_test.py

from hello import *

def test_hello():
    assert hello() == "Hello"

Additional info

The >Python: Debug All Tests command works fine. Tests are run, I can debug them, message "x passed in y" is printed to Debug Console

Logs

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

> ~\AppData\Local\Programs\Python\Python37\python.exe "c:/Users/Vaust XIII/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py" pytest --override-ini junit_family=xunit1 --rootdir e:\python\foo --junit-xml=C:\Users\VAUSTX~1\AppData\Local\Temp\tmp-2288ORjzo6SAoZsg.xml .
cwd: e:\python\foo
> ~\AppData\Local\Programs\Python\Python37\python.exe "c:/Users/Vaust XIII/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py" pytest --override-ini junit_family=xunit1 --rootdir e:\python\foo --junit-xml=C:\Users\VAUSTX~1\AppData\Local\Temp\tmp-2288ORjzo6SAoZsg.xml .
cwd: e:\python\foo

type-bug

All 5 comments

Hi! I'm running into the same problem, with a pyenv and poetry virtual environments. I can debug tests but running them from the GUI produces this error. How is #14108 fixing this? I don't understand.

Update: I can run tests only if I do pip install ., using -e alone is not enough. With poetry, I can't find a way to obtain this result.

My setup:

  • VS Code version:
    $code --version 1.51.0 fcac248b077b55bae4ba5bab613fd6e9156c2f0c x64
  • Extension version (available under the Extensions sidebar): v2020.11.311084263-dev
  • OS and version: Linux Mint 19.3 Tricia
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.0
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): (pyenv + virtualenv extension) and poetry
  • Relevant/affected Python packages and their versions: pytest==6.1.2
  • Relevant/affected Python-related VS Code extensions and their versions:
  • Value of the python.languageServer setting: Pylance

Can we reopen this issue?

The issue here was that the JSON returned was either empty or not parse-able. TypeError: Cannot read property 'testsuites' of null is a side effect of that. This particular issue was where we we quoting the script name twice, which caused python to treat it differently (as relative path), than when it is quoted once.

Also, test discovery issues with editable installs (pip install . -e) are is due to this bug #14570.

If test discovery is not working, try running the command it shows there in the test log to see if the JSON generated is parse able. If you are not able to see where the command is. Please file a separate bug.

@diegoquintanav I have run into the same problem:

Exception: pytest discovery failed (exit code 2)

python /home/jfn/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jfn/source/github.com/prometheus-adaptive-cards -s tests
python /home/jfn/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jfn/source/github.com/prometheus-adaptive-cards -s --cache-clear tests
python /home/jfn/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jfn/source/github.com/prometheus-adaptive-cards -s --cache-clear tests
python /home/jfn/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jfn/source/github.com/prometheus-adaptive-cards -s --cache-clear tests
python /home/jfn/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jfn/source/github.com/prometheus-adaptive-cards -s --cache-clear tests
python /home/jfn/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jfn/source/github.com/prometheus-adaptive-cards -s --cache-clear tests
python /home/jfn/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jfn/source/github.com/prometheus-adaptive-cards -s --cache-clear tests
python /home/jfn/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jfn/source/github.com/prometheus-adaptive-cards -s --cache-clear tests
ImportError while loading conftest '/home/jfn/source/github.com/prometheus-adaptive-cards/tests/conftest.py'.
tests/conftest.py:8: in <module>
    from prometheus_adaptive_cards.config.logger import setup_logging
E   ModuleNotFoundError: No module named 'prometheus_adaptive_cards'
Error: TypeError: Cannot read property 'testsuites' of null

The alternative test suite "Test explorer" works fine btw

@trallnag Yes, following a lead from the comment @karthiknadig gave, I found this issue ->https://github.com/microsoft/vscode-python/issues/14579#issuecomment-719643722

At the moment, using an older version of the extension solved my problem.

Was this page helpful?
0 / 5 - 0 ratings