microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.28k stars 1.17k forks source link

Test Discovery Failed after updating VS Code #8697

Closed oji closed 4 years ago

oji commented 4 years ago

Environment data

Version: 1.40.1
Commit: 8795a9889db74563ddd43eb0a897a2384129a619
Date: 2019-11-13T16:47:44.719Z
Electron: 6.1.2
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Darwin x64 18.7.0

Expected behaviour

When running Python: Discover Test command, tests are discovered and I'm able to run them from the IDE. (It was working before the VS Code update)

Actual behaviour

I get Test Discovery Failed errror

Steps to reproduce:

  1. Run Python: Discover Tests command

Logs

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

Python Output:

> ~/apps/someapp/.conda/envs/logger/bin/python ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/apps/someapp -s --cache-clear test
cwd: ~/apps/someapp
> ~/apps/someapp/.conda/envs/logger/bin/python ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/apps/someapp -s --cache-clear test
cwd: ~/apps/someapp

Python Test Logs output:

python /Users/someone/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /Users/someone/apps/someapp -s --cache-clear test
Test Discovery failed: 
SyntaxError: Unexpected end of JSON input

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)

  ERR TreeError [MarkersPanel] Tree element not found: [object Object]: Error: TreeError [MarkersPanel] Tree element not found: [object Object]
    at t.ObjectTreeModel.getElementLocation (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:133:120)
    at t.ObjectTreeModel.isCollapsed (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:132:250)
    at W.isCollapsed (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1043:391)
    at z.revealMarkersForCurrentActiveEditor (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:5926:628)
    at z.autoReveal (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:5926:485)
    at z.onActiveEditorChanged (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:5923:776)
    at file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:5922:754
    at file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:111:709
    at c.fire (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:115:286)
    at e.doEmitActiveEditorChangeEvent (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4909:172)
    at e.handleActiveEditorChange (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4908:992)
    at file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4909:282
    at c.fire (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:115:286)
    at file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:5569:875
    at runNextTicks (internal/process/task_queues.js:55:5)
    at processImmediate (internal/timers.js:412:9)
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:16: Cached data exists getEnvironmentVariables, /Users/someone/apps/someapp
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:18: Cached data exists getEnvironmentVariables, /Users/someone/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/jedi/third_party/typeshed/stdlib/2and3/builtins.pyi
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:18: > ~/apps/someapp/.conda/envs/logger/bin/python -m flake8 --ignore E501 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/jedi/third_party/typeshed/stdlib/2and3/builtins.pyi
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:18: cwd: ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/jedi/third_party/typeshed/stdlib/2and3
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:18: > ~/apps/someapp/.conda/envs/logger/bin/python -m flake8 --ignore E501 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/jedi/third_party/typeshed/stdlib/2and3/builtins.pyi
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:18: cwd: ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/jedi/third_party/typeshed/stdlib/2and3
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: Cached data exists getEnvironmentVariables, /Users/someone/apps/someapp
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: Get Conda environments, Class name = b, completed in 0ms, Arg 1: false, Return Value: undefined
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: Cached data exists getEnvironmentVariables, <No Resource>
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: > conda env list
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: Failed to get conda environment list from conda [Error: spawn conda ENOENT  at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)   at onErrorNT (internal/child_process.js:456:16) at processTicksAndRejections (internal/process/task_queues.js:84:9)] {  errno: 'ENOENT',  code: 'ENOENT',  syscall: 'spawn conda',  path: 'conda',  spawnargs: [ 'env', 'list' ]}
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: Get Conda environments, Class name = b, completed in 20ms, Arg 1: true, Return Value: undefined
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: Activation Commands received undefined for shell bash
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: getActivatedEnvironmentVariables, Class name = b, completed in 28ms, Arg 1: <Uri:/Users/someone/apps/someapp>, Arg 2: undefined, Arg 3: false
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: Cached data exists getEnvironmentVariables, /Users/someone/apps/someapp
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: > ~/apps/someapp/.conda/envs/logger/bin/python ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/apps/someapp -s --cache-clear test
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: cwd: ~/apps/someapp
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: > ~/apps/someapp/.conda/envs/logger/bin/python ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/apps/someapp -s --cache-clear test
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: cwd: ~/apps/someapp
console.ts:137 [Extension Host] Error Python Extension: 2019-11-20 17:03:20: Failed to parse discovered Test [Error:    at m.discoverTests (/Users/someone/.vscode/extensions/ms-python.python-2019.11.49689/out/client/extension.js:75:1234891)]
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:580
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:580
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-11-20 17:03:20: Failed to parse discovered Test [SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at m.discoverTests (/Users/someone/.vscode/extensions/ms-python.python-2019.11.49689/out/client/extension.js:75:1234764)]
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:580
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:580
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
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:580
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:580
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:580
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-11-20 17:03:20: Python Extension: displayDiscoverStatus [SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at m.discoverTests (/Users/someone/.vscode/extensions/ms-python.python-2019.11.49689/out/client/extension.js:75:1234764)]
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:580
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:580
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] Info Python Extension: 2019-11-20 17:03:20: Cached data exists getEnvironmentVariables, /Users/someone/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/jedi/third_party/typeshed/stdlib/2and3/builtins.pyi
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: > ~/apps/someapp/.conda/envs/logger/bin/python -m flake8 --ignore E501 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/jedi/third_party/typeshed/stdlib/2and3/builtins.pyi
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: cwd: ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/jedi/third_party/typeshed/stdlib/2and3
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: > ~/apps/someapp/.conda/envs/logger/bin/python -m flake8 --ignore E501 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/jedi/third_party/typeshed/stdlib/2and3/builtins.pyi
console.ts:137 [Extension Host] Info Python Extension: 2019-11-20 17:03:20: cwd: ~/.vscode/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/jedi/third_party/typeshed/stdlib/2and3
aldeo commented 4 years ago

I get the same error after updating to VS 14.0.1. My extension version is the same as well, but running Python 3.7.2 64-bit

oozut commented 4 years ago

Hi, I have the same issue from yesterday and the lastest update of the python extension.

Version: 1.40.1 Commit: 8795a9889db74563ddd43eb0a897a2384129a619 Date: 2019-11-13T16:49:35.976Z Electron: 6.1.2 Chrome: 76.0.3809.146 Node.js: 12.4.0 V8: 7.6.303.31-electron.0 OS: Windows_NT x64 6.1.7601

Extension version (available under the Extensions sidebar): 2019.11.49689 Python version (& distribution if applicable, e.g. Anaconda): python 3.5.2, custom, pytest 3.0.3 Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info #3977): Language Server

discoverTests: python c:\Users\u613766.vscode\extensions\ms-python.python-2019.11.49689\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir c:\Users\u613766\Source\Repos\metallopy -s --cache-clear Test Discovery failed: SyntaxError: Unexpected end of JSON input

Running the command into a standard python console pointed to the current conda environement: python c:\Users\u613766.vscode\extensions\ms-python.python-2019.11.49689\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir c:\Users\u613766\Source\Repos\metallopy -s --cache-clear

Returns nothing to the stdout.

Running the command into a standard python console pointed to the current conda environement: python c:\Users\u613766.vscode\extensions\ms-python.python-2019.11.49689\pythonFiles\testing_tools\run_adapter.py discover pytest -- -rootdir c:\Users\u613766\Source\Repos\metallopy -s --cache-clear

Please see the single dash before the rootdir arguments Returns the expected json to stdout.

oozut commented 4 years ago

Looking into the out\client\extension.js and replacing all the reference from "--rootdir" to "-rootdir" seems to have solved the issue of the discovery. However, I cannot run individual tests after that. I can only run all the tests.

brettcannon commented 4 years ago

@oji What version of pytest are you using? And any chance you can provide a small reproducer (we quickly tested and it works for us so we will

@aldeo what version of pytest are you using? And are you using VS Code 1.40.1 or are you actually using Visual Studio 14? And did this work before? And do you have any code that prints to stdout during test discovery (e.g. some hook that automatically runs which prints information)?

@oozut any difference if you update to a newer version of pytest (3.0.3 is over 3 years old)? And did this work before? And do you have any code that prints to stdout during test discovery (e.g. some hook that automatically runs which prints information)?

oji commented 4 years ago

@brettcannon I'm using pytest 3.1.3. I updated to 5.3.0, and now it works. It was working with 3.1.3 and previous version of VS Code, though.

Thanks a lot!

karthiknadig commented 4 years ago

Since this issue was resolved for by upgrading to the latest version of pytest. we are going to close this one. Please open a separate bug if upgrading pytest does not address the issue.

oozut commented 4 years ago

@brettcannon Hi, unfortunately, I run behind a corporate proxy with a restricted set of available library so updating the version of pytest cannot be done in a straightforward manner. For info, the feature works perfectly before it just changed to the latest version. I find a downgraded version of ms-python for vscode so I will use it until I am able to change the version of pytest on the private repository. Thanks for the response.

brettcannon commented 4 years ago

@oozut unfortunately we needed to make a change adding --rootdir to better support recent versions of pytest and that breaks old versions of pytest which don't support that CLI option.

You can still run tests in the terminal to avoid having to downgrade the extension until you're able to upgrade pytest if you can live without the Test Explorer.