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.

Spawn for running test discovery is not following symlinks properly.

See original GitHub issue

Environment data

  • VS Code version: 1.41.1 26076a4de974ead31f97692a0d32f90d735645c0
  • Extension version (available under the Extensions sidebar): 2019.11.50794
  • OS and version: Fedora Linux 31
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
  • Relevant/affected Python packages and their versions: Python 3.7.5, pytest-4.6.7, py-1.8.0, pluggy-0.12.0
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info #3977): “python.jediEnabled”: true

Expected behaviour

tests are detected

Actual behaviour

tests are not detected, error is issues, running the adapter returns:

$ python /home/jp/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jp/py/vscode -s --cache-clear
[{"rootid": ".", "root": "/home/jp/py/vscode", "parents": [{"id": "./test_simple.py", "kind": "file", "name": "test_simple.py", "parentid": ".", "relpath": "./test_simple.py"}], "tests": [{"id": "./test_simple.py::test_simple", "name": "test_simple", "source": "./test_simple.py:1", "markers": [], "parentid": "./test_simple.py"}]}]

Steps to reproduce:

  1. Create minimal repo with:
$ cat test_simple.py 
def test_simple():
    assert 2 + 2 == 4
$ cat .vscode/settings.json 
{
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pytestEnabled": true
}
  1. run:

code .

  1. open test_simple.py and click Discover Tests

Logs

python /home/jp/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jp/py/vscode -s --cache-clear
Test Discovery failed: 
TypeError: Cannot read property 'uri' of undefined

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)

console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: Cached data exists ActivatedEnvironmentVariables, /home/jp/py/vscode
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: getActivatedEnvironmentVariables, Class name = b, completed in 1ms, Arg 1: <Uri:/home/jp/py/vscode>, Arg 2: undefined, Arg 3: false
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: Cached data exists getEnvironmentVariables, /home/jp/py/vscode
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: > /usr/bin/python ~/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/py/vscode -s --cache-clear
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: cwd: ~/python-etl/base-code
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: > /usr/bin/python ~/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/py/vscode -s --cache-clear
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: cwd: ~/python-etl/base-code
notificationsAlerts.ts:40 Test discovery error, please check the configuration settings for the tests.
onDidNotificationChange @ notificationsAlerts.ts:40
(anonymous) @ notificationsAlerts.ts:26
fire @ event.ts:581
addNotification @ notifications.ts:171
notify @ notificationService.ts:101
(anonymous) @ mainThreadMessageService.ts:83
_showMessage @ mainThreadMessageService.ts:44
$showMessage @ mainThreadMessageService.ts:38
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
console.ts:137 [Extension Host] Error Python Extension: 2019-12-31 20:05:50: Python Extension: displayDiscoverStatus [TypeError: Cannot read property 'uri' of undefined	at /home/jp/.vscode/extensions/ms-python.python-2019.11.50794/out/client/extension.js:1:475432]
t.log @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:26 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
dam0vm3ntcommented, Mar 25, 2021

It turns out that the problem for me was on how the workspace was opened. When using:

  • code ~\path\my.code-workspace it is not working, while
  • code c:\Users\user\path\my.code-workspace than it’s working

This is because the final command created by the extension will give the workspace path to the discovery agent inside simple quotes and thus special characters won’t work anymore. Hope this can help.

0reactions
JacekPliszkacommented, Jul 21, 2021

I think it is not only special characters

code .

does not work for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode pytest test discovery fails - python - Stack Overflow
I spent ages trying to decipher this unhelpful error after creating a test that had import errors. Verify that your test suite can...
Read more >
User and Workspace Settings - Visual Studio Code
To open the Settings editor, use the following VS Code menu command: On Windows/Linux - File > Preferences > Settings; On macOS -...
Read more >
Changelog — pytest documentation
#10060: When running with --pdb , TestCase.tearDown is no longer called for tests when the class has been skipped via unittest.skip or pytest.mark....
Read more >
Understanding and Exploiting Symbolic links in Windows
Not to forget that it may get tricky to exploit many scenarios you may come across to abusing symlink if you don't have...
Read more >
Windows Suspicious Process | InsightIDR Documentation
Attacker Technique - Batch File Executing Powershell To Spawn Python.exe ... Attacker Technique - FSUtil Enables Remote Symbolic Links on Windows ...
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