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.

pytest runner fails to populate problems, throws TypeError

See original GitHub issue

Environment data

  • VS Code version: 1.42.0-insider (8d4cdbaa)
  • Extension version (available under the Extensions sidebar): 2020.1.58038
  • OS and version: Ubuntu 18.04
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.9
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
  • Relevant/affected Python packages and their versions: pytest
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info #3977): Language Server

Expected behaviour

Running pytest with a failing output should produce messages detailing the failure, via testMessageService.ts, and populate the “problems” tab with the failing tests.

Actual behaviour

A message is displayed showing The "path" argument must be of type string. Received type "undefined"

With the following stack trace

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:107)
    at Object.isAbsolute (path.js:1027)
    at f.isAbsolute [as getLocationStack] (/home/ubuntu/.vscode…ssageService.ts:111)
    at processTicksAndRejections (internal/process/task_queues.js:89)
    at f.locationStack [as getFilteredTestMessages] (/home/ubuntu/.vscode…essageService.ts:62)
    at t.TestManager.messages [as runTestImpl] (/home/ubuntu/.vscode…g/pytest/main.ts:48)

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Checkout this minimal example project https://github.com/Arnatious/vscode-python-pytest-repro
  2. Change python interpreter if needed
  3. Discover and run tests.

Logs

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

User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'WebHostNotebook - control'
> conda --version
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> conda info --json
Starting Microsoft Python language server.
> /usr/bin/python3 ~/.vscode-server-insiders/extensions/ms-python.python-2020.1.58038/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/workspace/minimal_repro -s --cache-clear test
cwd: ~/workspace/minimal_repro
> /usr/bin/python3 ~/.vscode-server-insiders/extensions/ms-python.python-2020.1.58038/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/workspace/minimal_repro -s --cache-clear test
cwd: ~/workspace/minimal_repro
> conda --version
> /usr/bin/python3 -m pytest --rootdir ~/workspace/minimal_repro --junitxml=/tmp/tmp-38321PLL2YDYzvzYH.xml test
cwd: ~/workspace/minimal_repro
> /usr/bin/python3 -m pytest --rootdir ~/workspace/minimal_repro --junitxml=/tmp/tmp-38321PLL2YDYzvzYH.xml test
cwd: ~/workspace/minimal_repro

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

There was an error in running the tests.
onDidNotificationChange @ notificationsAlerts.ts:40
notificationsAlerts.ts:38 TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:107)
    at Object.isAbsolute (path.js:1027)
    at f.isAbsolute [as getLocationStack] (/home/ubuntu/.vscode-server-insiders/extensions/ms-python.python-2020.1.58038/src/client/testing/pytest/services/testMessageService.ts:111)
    at processTicksAndRejections (internal/process/task_queues.js:89)
    at f.locationStack [as getFilteredTestMessages] (/home/ubuntu/.vscode-server-insiders/extensions/ms-python.python-2020.1.58038/src/client/testing/pytest/services/testMessageService.ts:62)
    at t.TestManager.messages [as runTestImpl] (/home/ubuntu/.vscode-server-insiders/extensions/ms-python.python-2020.1.58038/src/client/testing/pytest/main.ts:48)

Additional info:

The directory structure is important to reproducing this bug, only when test and the module are in sibling directories does this error occur

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
pe224commented, May 3, 2020

I am also seeing this error - a work around that may work for people is, if you you’re setting junit_family = xunit2 in either pytest.ini or in your settings.json python.testing.pytestArgs either remove this or specify xunit1 instead and it should start working again.

Can confirm this. When running pytest (5.4.1) with default settings I receive following deprecation warning

PytestDeprecationWarning: The 'junit_family' default value will change to 'xunit2' in pytest 6.0.
  Add 'junit_family=xunit1' to your pytest.ini file to keep the current format in future versions of pytest and silence this warning.

Setting junit_family manually to xunit2 generates the error - but only when some tests fail! Setting it to xunit1 and everything is fine.

Since xunit2 will be the new default this looks like it is only a temporary workaround and needs to be solved properly.

6reactions
keke8273commented, Feb 22, 2020

I can reproduce the same error on windows with Python extension 2020.2.64397

Version: 1.42.1 (user setup)
Commit: c47d83b293181d9be64f27ff093689e8e7aed054
Date: 2020-02-11T14:45:59.656Z
Electron: 6.1.6
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.17763
pytest         5.3.5
pytest-cov     2.8.1
Read more comments on GitHub >

github_iconTop Results From Across the Web

pytest cannot be executed from Python 3.10.4 - Stack Overflow
I am having the same problem, Python 3.10.4 and pytest 7.1.2, when I start command: $ pipenv run pytest. I get an error:...
Read more >
How to Throw Exceptions in Python - Rollbar
Fortunately, Python comes with a robust error handling framework. ... Python throws the TypeError exception when there are wrong data types.
Read more >
Effective Python Testing With Pytest
In this tutorial, you'll learn how to take your testing to the next level with pytest. You'll cover intermediate and advanced pytest ......
Read more >
_pytest.fixtures — pytest documentation
instance is not None: # Bind the unbound method to the TestCase instance. fixturefunc = fixturedef.func.__get__(request.instance) # type: ignore[union-attr] ...
Read more >
Uncaught TypeError: Cannot read property of undefined
The error most often than not is faced when the scripts come across uninitialized variable or object. Description. 'Undefined' is the property ...
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