Skip to content

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

Closed

Description

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%

Activity

  1. added
    triage-needed
    on Jun 11, 2022
  2. added
    bug
    on Jun 13, 2022
  3. karthiknadig commented on Jun 13, 2022

    @karthiknadig
    Member

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

  4. added
    info-needed
    on Jun 13, 2022
  5. mathieuackermann commented on Jun 13, 2022

    @mathieuackermann
    Author

    Karthik Nadig (@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 }

  6. karthiknadig commented on Jun 13, 2022

    @karthiknadig
    Member

    Mathieu Ackermann (@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
    
  7. mathieuackermann commented on Jun 13, 2022

    @mathieuackermann
    Author

    Karthik Nadig (@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)
    
  8. karthiknadig commented on Jun 13, 2022

    @karthiknadig
    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
    
  9. mathieuackermann commented on Jun 14, 2022

    @mathieuackermann
    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?

  10. karthiknadig commented on Jun 14, 2022

    @karthiknadig
    Member

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

  11. mathieuackermann commented on Jun 14, 2022

    @mathieuackermann
    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"}]}]

  12. karthiknadig commented on Jun 14, 2022

    @karthiknadig
    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.

  13. mathieuackermann commented on Jun 14, 2022

    @mathieuackermann
    Author

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

    pytestdata.json.txt

  14. karthiknadig commented on Jun 14, 2022

    @karthiknadig
    Member

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

    Kartik Raj (@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.

  15. ehawman commented on Jun 24, 2022

    @ehawman

    Karthik Nadig (@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?

  16. added
    investigating
    on Jun 24, 2022
  17. karthiknadig commented on Jun 24, 2022

    @karthiknadig
    Member

    Evan Hawman (@ehawman) Kartik Raj (@karrtikr) I don't think we detect Nushell, that would be a feature request.

  18. ehawman commented on Jun 24, 2022

    @ehawman
  19. removed
    investigating
    on Jul 7, 2022
  20. mathieuackermann commented on Jul 13, 2022

    @mathieuackermann
    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.

  21. locked as resolved and limited conversation to collaborators on Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testingbuginfo-neededtriage-needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions