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

VSCode failed to discover pytest unit tests: overwriting env vars #21535

Closed
Cuizi7 opened this issue Jun 29, 2023 · 14 comments
Closed

VSCode failed to discover pytest unit tests: overwriting env vars #21535

Cuizi7 opened this issue Jun 29, 2023 · 14 comments
Assignees
Labels
area-testing info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@Cuizi7
Copy link

Cuizi7 commented Jun 29, 2023

Type: Bug

Error messages shows in Test Explorer: Pytest Discovery Error:
image
Messages shown in OUTPUT > Python:
image
But "pytest --collect-only" works fine
image

Please help me to solve this problem, thank you very much.

Extension version: 2023.10.1
VS Code version: Code - Insiders 1.80.0-insider (Universal) (49b8e2d5410795e5a23a9c6b7f99b97f4afb4b47, 2023-06-23T13:51:01.857Z)
OS version: Darwin arm64 22.5.0
Modes:

System Info
Item Value
CPUs Apple M2 Pro (12 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 3, 4, 4
Memory (System) 32.00GB (0.41GB free)
Process Argv --crash-reporter-id 4b71a7cf-7aef-4fd8-819a-3e313884e06c --crash-reporter-id 4b71a7cf-7aef-4fd8-819a-3e313884e06c
Screen Reader no
VM 0%
A/B Experiments
vsliv695:30137379
vsins829:30139715
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythontb:30258533
pythonptprofiler:30281269
vshan820:30294714
vscod805:30301674
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30404738
py29gd2263:30776702
vsclangdf:30492506
c4g48928:30535728
dsvsc012:30540252
pynewext54:30618038
pylantcb52:30590116
pyind779:30611226
pythonsymbol12:30651887
showlangstatbar:30737417
pythonms35:30671666
pythonfmttext:30716741
pythoncmvfstr:30726892
fixshowwlkth:30771523
showindicator:30766888
pythongtdpath:30726887
gsofb:30778559
e440d664:30776459
pythonnosmt12:30773574
pythonidxpt:30768918
pythondjangots:30768917
pythonnoceb:30776497
e537b577:30772214
asynctok:30776451
dsvsc013:30777762
dsvsc014:30777825

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jun 29, 2023
@eleanorjboyd
Copy link
Member

Hi! Are you on insiders? We have just launched a new testing infrastructure and this could be the problem. You can test this as well by setting "python.experiments.optOutFrom": ["pythonTestAdapter"], in your user settings on insiders to see if it works without the experiment. Thanks!

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jun 29, 2023
@Cuizi7
Copy link
Author

Cuizi7 commented Jun 30, 2023

@eleanorjboyd Thanks for the reply. I just modified the settings as you mentioned, but the problem still exists. I also tried a release version of VSCode, the problem behaves exactly the same as the insiders version:

image

The version info of the release version I've tryied:

Version: 1.79.2 (Universal)
Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06
Date: 2023-06-14T08:58:52.392Z
Electron: 22.5.7
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 22.5.0

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Jun 30, 2023
@eleanorjboyd
Copy link
Member

will investigate- thanks!

@eleanorjboyd
Copy link
Member

Hello! Could you send the full logs from the python output with the settings "python.analysis.logLevel": "Trace", and "python.experiments.optInto": ["pythonTestAdapter"], (then reload the window). It seems that this problem exists on both the rewrite and the stable version of our testing so it would be easier for me to help on the rewrite as that is the logic we are switching to moving forward. Thank you for your assistance!

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jul 7, 2023
@Cuizi7
Copy link
Author

Cuizi7 commented Jul 10, 2023

@eleanorjboyd The full logs are as follow:

2023-07-10 09:27:04.826 [info] Experiment 'pythonaa' is active
2023-07-10 09:27:04.826 [info] Experiment 'pythonPromptNewFormatterExt' is active
2023-07-10 09:27:04.826 [info] Experiment 'pythonPromptNewToolsExt' is active
2023-07-10 09:27:04.826 [info] Test server listening.
2023-07-10 09:27:04.826 [info] Python interpreter path: ~/miniconda3/envs/py310/bin/python
2023-07-10 09:27:04.860 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 09:27:04.860 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 09:27:05.236 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 09:27:05.236 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 09:27:05.236 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 09:27:05.236 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 09:27:05.236 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 09:27:05.236 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 09:27:05.236 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 09:27:06.463 [info] Starting Pylance language server.
2023-07-10 09:27:06.476 [info] > conda info --json
2023-07-10 17:15:53.148 [info] Experiment 'pythonaa' is active
2023-07-10 17:15:53.148 [info] Experiment 'pythonPromptNewFormatterExt' is active
2023-07-10 17:15:53.148 [info] Experiment 'pythonPromptNewToolsExt' is active
2023-07-10 17:15:53.164 [info] Test server listening.
2023-07-10 17:15:53.165 [info] Python interpreter path: ~/miniconda3/envs/py310/bin/python
2023-07-10 17:15:53.591 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 17:15:53.591 [warning] Retry failed, storage update failed for key PYTHON_GLOBAL_STORAGE_KEYS
2023-07-10 17:15:54.423 [info] Starting Pylance language server.
2023-07-10 17:15:54.433 [info] > conda info --json
2023-07-10 17:17:58.024 [info] Discover tests for workspace name: trading - uri: /Users/cuiziqi/Workspace/trading
2023-07-10 17:17:58.027 [info] > conda run -n py310 --no-capture-output python ~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/get_output_via_markers.py ~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/printEnvVariables.py
2023-07-10 17:17:58.027 [info] shell: bash
2023-07-10 17:17:58.661 [info] > conda run -n py310 --no-capture-output python ~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/get_output_via_markers.py ~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear
2023-07-10 17:17:58.661 [info] cwd: .
2023-07-10 17:18:00.509 [error] Error discovering pytest tests:
 n [Error]: WARNING: overwriting environment variables set in the machine
overwriting variable {'PYTORCH_ENABLE_MPS_FALLBACK'}

    at ChildProcess.<anonymous> (/Users/cuiziqi/.vscode-insiders/extensions/ms-python.python-2023.12.0/out/client/extension.js:2:241817)
    at Object.onceWrapper (node:events:628:26)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1121:16)
    at Socket.<anonymous> (node:internal/child_process:479:11)
    at Socket.emit (node:events:513:28)
    at Pipe.<anonymous> (node:net:757:14)
2023-07-10 17:22:47.896 [info] Experiment 'pythonTestAdapter' is active
2023-07-10 17:22:47.897 [info] Experiment 'pythonaa' is active
2023-07-10 17:22:47.897 [info] Experiment 'pythonPromptNewFormatterExt' is active
2023-07-10 17:22:47.897 [info] Experiment 'pythonPromptNewToolsExt' is active
2023-07-10 17:22:47.911 [info] Test server listening.
2023-07-10 17:22:47.911 [info] Python interpreter path: ~/miniconda3/envs/py310/bin/python
2023-07-10 17:22:49.202 [info] Starting Pylance language server.
2023-07-10 17:22:49.208 [info] > conda info --json
2023-07-10 17:23:09.613 [info] Discover tests for workspace name: trading - uri: /Users/cuiziqi/Workspace/trading
2023-07-10 17:23:09.614 [info] Running discovery for pytest using the new test adapter.
2023-07-10 17:23:09.616 [info] > conda run -n py310 --no-capture-output python ~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/get_output_via_markers.py ~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/printEnvVariables.py
2023-07-10 17:23:09.616 [info] shell: bash
2023-07-10 17:23:10.151 [info] > conda run -n py310 --no-capture-output python ~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/get_output_via_markers.py -m pytest -p vscode_pytest --collect-only
2023-07-10 17:23:10.151 [info] cwd: .
2023-07-10 17:23:11.554 [info] Test server connected to a client.
2023-07-10 17:23:11.555 [info] Using result resolver for discovery
2023-07-10 17:23:11.682 [error] Error while trying to run pytest discovery, 
Error: WARNING: overwriting environment variables set in the machine
overwriting variable {'PYTORCH_ENABLE_MPS_FALLBACK'}



2023-07-10 17:23:11.683 [error] pytest test discovery error
 n [Error]: WARNING: overwriting environment variables set in the machine
overwriting variable {'PYTORCH_ENABLE_MPS_FALLBACK'}

    at ChildProcess.<anonymous> (/Users/cuiziqi/.vscode-insiders/extensions/ms-python.python-2023.12.0/out/client/extension.js:2:241817)
    at Object.onceWrapper (node:events:628:26)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1121:16)
    at Socket.<anonymous> (node:internal/child_process:479:11)
    at Socket.emit (node:events:513:28)
    at Pipe.<anonymous> (node:net:757:14)
2023-07-10 17:24:45.419 [info] Experiment 'pythonTestAdapter' is active
2023-07-10 17:24:45.419 [info] Experiment 'pythonaa' is active
2023-07-10 17:24:45.419 [info] Experiment 'pythonPromptNewFormatterExt' is active
2023-07-10 17:24:45.419 [info] Experiment 'pythonPromptNewToolsExt' is active
2023-07-10 17:24:45.462 [info] Test server listening.
2023-07-10 17:24:45.463 [info] Python interpreter path: ~/miniconda3/envs/py310/bin/python
2023-07-10 17:24:46.756 [info] Starting Pylance language server.
2023-07-10 17:24:46.760 [info] > conda info --json
2023-07-10 17:25:24.520 [info] Experiment 'pythonTestAdapter' is active
2023-07-10 17:25:24.520 [info] Experiment 'pythonaa' is active
2023-07-10 17:25:24.520 [info] Experiment 'pythonPromptNewFormatterExt' is active
2023-07-10 17:25:24.520 [info] Experiment 'pythonPromptNewToolsExt' is active
2023-07-10 17:25:24.533 [info] Test server listening.
2023-07-10 17:25:24.533 [info] Python interpreter path: ~/miniconda3/envs/py310/bin/python
2023-07-10 17:25:25.786 [info] Starting Pylance language server.
2023-07-10 17:25:25.791 [info] > conda info --json
2023-07-10 17:25:26.649 [info] Discover tests for workspace name: trading - uri: /Users/cuiziqi/Workspace/trading
2023-07-10 17:25:26.649 [info] Running discovery for pytest using the new test adapter.
2023-07-10 17:25:26.651 [info] > conda run -n py310 --no-capture-output python ~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/get_output_via_markers.py ~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/printEnvVariables.py
2023-07-10 17:25:26.651 [info] shell: bash
2023-07-10 17:25:27.227 [info] > conda run -n py310 --no-capture-output python ~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/get_output_via_markers.py -m pytest -p vscode_pytest --collect-only
2023-07-10 17:25:27.227 [info] cwd: .
2023-07-10 17:25:28.653 [info] Test server connected to a client.
2023-07-10 17:25:28.654 [info] Using result resolver for discovery
2023-07-10 17:25:28.778 [error] Error while trying to run pytest discovery, 
Error: WARNING: overwriting environment variables set in the machine
overwriting variable {'PYTORCH_ENABLE_MPS_FALLBACK'}



2023-07-10 17:25:28.779 [error] pytest test discovery error
 n [Error]: WARNING: overwriting environment variables set in the machine
overwriting variable {'PYTORCH_ENABLE_MPS_FALLBACK'}

    at ChildProcess.<anonymous> (/Users/cuiziqi/.vscode-insiders/extensions/ms-python.python-2023.12.0/out/client/extension.js:2:241817)
    at Object.onceWrapper (node:events:628:26)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1121:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)

Even though I changed the settings as you mentioned, the logs don't seem to be getting much more. Hope I'm doing the right thing, thanks.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Jul 10, 2023
@eleanorjboyd
Copy link
Member

Hello! Given the fact that you see it both with and without the rewrite as well as the specific error message, I am not sure if it is actually caused by vscode. To check could you run this command from a non-activated environment conda run -n py310 --no-capture-output -m pytest --collect-only? Also try running python -m pytest from an activated environment. Do either of those fail with the same error message? If so then it might be configuration related.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jul 12, 2023
@Cuizi7
Copy link
Author

Cuizi7 commented Jul 13, 2023

@eleanorjboyd the conda run command does not have the -m argument. If I'm not mistaken, you meant conda run -n py310 --no-capture-output python -m pytest --collect-only. This command seems to work fine, which has following output:
image

The other command works fine too:
image

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Jul 13, 2023
@eleanorjboyd
Copy link
Member

Thank you for trying those steps! I will need to do some work on my end before I can ask you to try something else but I am working on debugging it. Thanks

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jul 13, 2023
@eleanorjboyd
Copy link
Member

Hi! Can you run this and send me back the whole output?
from the terminal:
export PYTHONPATH=~/.vscode-insiders/extensions/ms-python.python-2023.12.0/pythonFiles/ (you might have to do the absolute path so just whatever comes before the .vscode-insiders folder)
conda run -n py310 --no-capture-output python -m pytest -p vscode_pytest --collect-only

@Cuizi7
Copy link
Author

Cuizi7 commented Jul 14, 2023

@eleanorjboyd thanks for the work. I found that unittests CAN be discovered when I open VSCode today, but the error messages are still shown in the output window, I'm not sure what happened.
image
image

I'm still willing to help you guys to debug. I ran commands you mentioned, the output is as follows(I can see plugin error here):
image

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Jul 14, 2023
@akarev0
Copy link

akarev0 commented Jul 14, 2023

Hi there, I used devcontainer for my work but I cannot now, I can discover the tests, but I cannot run it because of incorrect path (as I can assume because debug setup with full path from launch.json works fine)

I am using following setting for my devcontainer:

"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
    "-c",
    "Tests/pytest.docker-compose.ini",
    "Tests"
]

but as I can see while I am trying to run test path starts from one folder inside and not tests folder, for example:
unit/test_third_api.py
while it should be:
Tests/unit/test_third_api.py
because path is incorrect I see Error: ERROR: file or directory not found: integration/...

Also color indication doesn't work at all I mean it doesn't representing any info, not green check marks nor red crosses

@eleanorjboyd
Copy link
Member

@Cuizi7, very interesting they can be discovered today. The screenshot you send is very helpful I will keep investigating!

@akarev0 could you file another issue for your bug? I can better assist there since it seems like a different issue. Thanks

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jul 14, 2023
@akarev0
Copy link

akarev0 commented Jul 14, 2023

@eleanorjboyd thanks, I hope I did everything right #21637 :)

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Jul 14, 2023
@eleanorjboyd eleanorjboyd changed the title VSCode failed to discover pytest unit tests VSCode failed to discover pytest unit tests: overwriting env vars Jul 17, 2023
@eleanorjboyd
Copy link
Member

closing as the issue is no longer appearing- please reopen if the issue surfaces again. Thanks

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jul 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing 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

3 participants