Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test discovery fails with " [n [Error]: & was unexpected at this time." #19285

Closed
mathieuackermann opened this issue Jun 11, 2022 · 15 comments
Closed
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@mathieuackermann
Copy link

mathieuackermann commented Jun 11, 2022

Issue Type: Bug

Steps to reproduce:

-Click on test beker
-Test discovery fails with "Error discovering pytest tests (see Output > Python)"
-In "Output", the following error is reported:

conda run -n insolinsights --no-capture-output python ~\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear
cwd: .
[ERROR 2022-5-11 18:53:8.626]: Error discovering pytest tests:
 [n [Error]: & was unexpected at this time.

	at ChildProcess.<anonymous> (c:\Users\mathi\.vscode\extensions\ms-python.python-2022.8.0\out\client\extension.js:2:232793)
	at Object.onceWrapper (node:events:510:26)
	at ChildProcess.emit (node:events:390:28)
	at maybeClose (node:internal/child_process:1064:16)
	at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)]

The same error occurs every time I save a Python file (as the test discovery runs automatically).
Pytest works fine when called directly from the terminal. Only the test explorer creates this error.

Expected output:

-Tests are correctly discovered

Extension version: 2022.8.0
VS Code version: Code 1.68.0 (4af164ea3a06f701fe3e89a2bcbb421d2026b68f, 2022-06-08T11:44:16.822Z)
OS version: Windows_NT x64 10.0.22000
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz (8 x 1498)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.60GB (7.01GB free)
Process Argv --crash-reporter-id 94bd11a9-8495-4db7-8f23-e7f7ed5117ac
Screen Reader no
VM 0%
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jun 11, 2022
@karthiknadig karthiknadig self-assigned this Jun 13, 2022
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug area-testing labels Jun 13, 2022
@karthiknadig
Copy link
Member

@mathieuackermann Can you share details about the tests that you are running? Is there by chance any particular test with & in its parameters?

@karthiknadig karthiknadig added the info-needed Issue requires more information from poster label Jun 13, 2022
@mathieuackermann
Copy link
Author

@karthiknadig no, I'm not using this character in any of the tests. Besides, all the tests are correctly discovered and run without issue if I run pytest directly from the terminal from the root of the workspace.
I'm not passing any parameter to pytest either. My only workspace settings are:

{ "python.testing.pytestEnabled": true, "python.testing.autoTestDiscoverOnSaveEnabled": false }

@karthiknadig
Copy link
Member

@mathieuackermann Can you run this from the terminal and share the output?

conda run -n insolinsights --no-capture-output python c:\Users\mathi\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\get_output_via_markers.py c:\Users\mathi\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear

@mathieuackermann
Copy link
Author

@karthiknadig here is the output:

& was unexpected at this time.
>>>PYTHON-EXEC-OUTPUT
<<<PYTHON-EXEC-OUTPUT
Traceback (most recent call last):
  File "c:\Users\mathi\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\get_output_via_markers.py", line 26, in <module>
    runpy.run_path(module, run_name="__main__")
  File "C:\Users\mathi\mambaforge\lib\runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "C:\Users\mathi\mambaforge\lib\runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "C:\Users\mathi\mambaforge\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\Users\mathi\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\testing_tools\run_adapter.py", line 17, in <module>
    from testing_tools.adapter.__main__ import parse_args, main
  File "c:\Users\mathi\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\testing_tools\adapter\__main__.py", line 9, in <module>
    from . import pytest, report
  File "c:\Users\mathi\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\testing_tools\adapter\pytest\__init__.py", line 7, in <module>     
    from ._discovery import discover
  File "c:\Users\mathi\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\testing_tools\adapter\pytest\_discovery.py", line 8, in <module>   
    import pytest
ModuleNotFoundError: No module named 'pytest'
ERROR conda.cli.main_run:execute(33): Subprocess for 'conda run ['python', 'c:\\Users\\mathi\\.vscode\\extensions\\ms-python.python-2022.8.0\\pythonFiles\\get_output_via_markers.py', 'c:\\Users\\mathi\\.vscode\\extensions\\ms-python.python-2022.8.0\\pythonFiles\\testing_tools\\run_adapter.py', 'discover', 'pytest', '--rootdir', '.', '-s', '--cache-clear']' command failed.  (See above for error)

@karthiknadig
Copy link
Member

Sorry, that pytest not found is due to a conda bug when double activation occurs due to conda run in an already activated terminal.

Can you try with this:

python c:\Users\mathi\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear

@mathieuackermann
Copy link
Author

Thanks! This latest command ran without error and produced a lot of output, listing all the tests in the terminal in JSON format. However the tests are still not displayed in the test explorer. How can I workaround that bug?

@karthiknadig
Copy link
Member

@mathieuackermann Can you share the output? something there must be causing this to happen.

@mathieuackermann
Copy link
Author

The output goes beyond the cache limit of the terminal, as there are many test combinations. Below is just a sample:

{"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MED-Stats.MIN-15]", "name": "test_israining_notraining[1-Stats.MED-Stats.MIN-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MED-Stats.MIN-60]", "name": "test_israining_notraining[1-Stats.MED-Stats.MIN-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MED-Stats.MAX-15]", "name": "test_israining_notraining[1-Stats.MED-Stats.MAX-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MED-Stats.MAX-60]", "name": "test_israining_notraining[1-Stats.MED-Stats.MAX-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MIN-Stats.AVG-15]", "name": "test_israining_notraining[1-Stats.MIN-Stats.AVG-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MIN-Stats.AVG-60]", "name": "test_israining_notraining[1-Stats.MIN-Stats.AVG-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MIN-Stats.MED-15]", "name": "test_israining_notraining[1-Stats.MIN-Stats.MED-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MIN-Stats.MED-60]", "name": "test_israining_notraining[1-Stats.MIN-Stats.MED-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MIN-Stats.MIN-15]", "name": "test_israining_notraining[1-Stats.MIN-Stats.MIN-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MIN-Stats.MIN-60]", "name": "test_israining_notraining[1-Stats.MIN-Stats.MIN-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MIN-Stats.MAX-15]", "name": "test_israining_notraining[1-Stats.MIN-Stats.MAX-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MIN-Stats.MAX-60]", "name": "test_israining_notraining[1-Stats.MIN-Stats.MAX-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MAX-Stats.AVG-15]", "name": "test_israining_notraining[1-Stats.MAX-Stats.AVG-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MAX-Stats.AVG-60]", "name": "test_israining_notraining[1-Stats.MAX-Stats.AVG-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MAX-Stats.MED-15]", "name": "test_israining_notraining[1-Stats.MAX-Stats.MED-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MAX-Stats.MED-60]", "name": "test_israining_notraining[1-Stats.MAX-Stats.MED-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MAX-Stats.MIN-15]", "name": "test_israining_notraining[1-Stats.MAX-Stats.MIN-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MAX-Stats.MIN-60]", "name": "test_israining_notraining[1-Stats.MAX-Stats.MIN-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MAX-Stats.MAX-15]", "name": "test_israining_notraining[1-Stats.MAX-Stats.MAX-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[1-Stats.MAX-Stats.MAX-60]", "name": "test_israining_notraining[1-Stats.MAX-Stats.MAX-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[2-Stats.AVG-Stats.AVG-15]", "name": "test_israining_notraining[2-Stats.AVG-Stats.AVG-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[2-Stats.AVG-Stats.AVG-60]", "name": "test_israining_notraining[2-Stats.AVG-Stats.AVG-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[2-Stats.AVG-Stats.MED-15]", "name": "test_israining_notraining[2-Stats.AVG-Stats.MED-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[2-Stats.AVG-Stats.MED-60]", "name": "test_israining_notraining[2-Stats.AVG-Stats.MED-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[2-Stats.AVG-Stats.MIN-15]", "name": "test_israining_notraining[2-Stats.AVG-Stats.MIN-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[2-Stats.AVG-Stats.MIN-60]", "name": "test_israining_notraining[2-Stats.AVG-Stats.MIN-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[2-Stats.AVG-Stats.MAX-15]", "name": "test_israining_notraining[2-Stats.AVG-Stats.MAX-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[2-Stats.AVG-Stats.MAX-60]", "name": "test_israining_notraining[2-Stats.AVG-Stats.MAX-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[2-Stats.MED-Stats.AVG-15]", "name": "test_israining_notraining[2-Stats.MED-Stats.AVG-15]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining[2-Stats.MED-Stats.AVG-60]", "name": "test_israining_notraining[2-Stats.MED-Stats.AVG-60]", "source": ".\\tests\\sensor_analyzer_test.py:201", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_notraining"}, {"id": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_raining[3-Stats.MAX-Stats.MAX-60]", "name": "test_israining_raining[3-Stats.MAX-Stats.MAX-60]", "source": ".\\tests\\sensor_analyzer_test.py:229", "markers": [], "parentid": "./tests/sensor_analyzer_test.py::TestSensorAnalyzer::test_israining_raining"}]}]

@karthiknadig
Copy link
Member

I see, try this, it should put the content into a file.

python c:\Users\mathi\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear > pytestdata.json

Please share the file pytestdata.json.

@mathieuackermann
Copy link
Author

Here it is (added .txt because GitHub refused to upload .json)

pytestdata.json.txt

@karthiknadig
Copy link
Member

@mathieuackermann Thanks for the data file. I looks fine, so I think the problem is elsewhere.

@karrtikr It seems like we are probably not using the right command here to invoke python. I suspect that we are using Powershell style command for something that is running on cmd? I will need your input on this.

@ehawman
Copy link

ehawman commented Jun 24, 2022

@karthiknadig I'm experiencing something similar. With Nushell, a new terminal instance tries to activate the selected venv with
& c:/Users/ehawman/Documents/Programming/Python/PA-FindReplace/.venv/Scripts/Activate.ps1
image

The correct command here should be
source c:/Users/ehawman/Documents/Programming/Python/PA-FindReplace/.venv/Scripts/activate.nu

Weirdly, when actually using pwsh it truncates the activation command:
sers/ehawman/Documents/Programming/Python/PA-FindReplace/.venv/Scripts/Activate.ps1, causing it to fail.
image

Do you think this falls under the same umbrella or should I start a new issue?

@karrtikr karrtikr self-assigned this Jun 24, 2022
@karrtikr karrtikr added the investigating We are looking into the cause of the issue label Jun 24, 2022
@karthiknadig
Copy link
Member

@ehawman @karrtikr I don't think we detect Nushell, that would be a feature request.

@ehawman
Copy link

ehawman commented Jun 24, 2022

@karthiknadig gotcha. thanks.

@karrtikr karrtikr removed the investigating We are looking into the cause of the issue label Jul 7, 2022
@mathieuackermann
Copy link
Author

Issue solved. For some reason, I had an obscure registry entry causing a crash of cmd.exe on startup, as described on this link: https://stackoverflow.com/questions/58849884/cmd-exe-closes-immediately-unusual-line-in-autorun-registry-entry
So the issue was not related to VS code or the Python extension.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants