-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
PYTEST_ADDOPTS env var not respected for test debug configuration with debugpy #22820
Comments
Hello! Could you include your logs from the @paulacamargo25 any other thoughts / suggestions on what to try to debug this? |
Sorry for the late reply. I will work on this and add it to the issue.
Thank you for following up on this.
|
Hi! So debugging and coverage don't work together (more on that here #19322). Seems like you are adding coverage in the test args then attempting to remove it in the debug launch config environment? So it seems like the pytest arg is being respected and not the env var correct? I think this is how pytest does precedence and therefore would be the expected outcome. |
Hi @eleanorjboyd so long story short, it appears this has been resolved in a recent update. I have modified my lauch.json to use debugpy again and I am able to get it to stop at breakpoints using the env var I'm now on Version: 1.89.0-insider Using launch config: {
"name": "Python: Debug Tests",
"type": "debugpy", // This used to not work
// "type": "python",
"request": "launch",
"program": "${file}",
"purpose": [
"debug-test"
],
"env": {
"PYTEST_ADDOPTS": "--no-cov",
},
"console": "integratedTerminal",
"justMyCode": true
}, And settings.json ...
"python.testing.pytestArgs": [
"--cov",
"--cov-report=html",
"-vvv",
"test",
]
... I can't comment on how pytest does precedence of args vs env vars. Quick search didn't make it clear for me. However, the VSCode documentation recommends the setup that I have (using the PYTEST_ADDOPTS env var) to disable coverage during debugging but allow coverage when running with the built in test runner. I had been using this for quite a while with From VSCode docs:
|
Hi @alenzo-arch, glad this is working! Generally the rule should be Command-line arguments take precedence over environment variables so if you run into a situation where that is not the case please let me know and I can look into it further. We do know that coverage and debugging doesn't work so we remove coverage args from the user args when calling debugging so it is likely having to do with that since we had an issue a few weeks ago with the arg parsing not working as desired. Generally this problem will be helped by our proposal to allow custom arguments per run type so hopefully we will get working on that soon and that could be useful to you. Thanks! |
Type: Bug
Behaviour
Expected vs. Actual
When using pytest-cov options are present in settings.json python.testing.pytestArgs, I would expect to be able to disable pytest-cov during test debugging when using the documenations suggested workaround of setting "env": {"PYTEST_ADDOPTS": "--no-cov" } in the test configuration with purpose "debug-test". This still works when specifying "type": "python" in the launch configuration, but when specifying "type": "debugpy" as suggested by the deprication warning, it does not.
Actual behaviour when "type": "debugpy" and "env": {"PYTEST_ADDOPTS": "--no-cov" } is set in launch configuration and "--cov" is included in python.testing.pytestArgs in settings.json, the test debugger does not stop on breakpoints. If I remove "--cov" form python.testing.pytestArgs or set "type": "python" in the launch config, breakpoints work as expected. It appears that the environment variables are being properly set in the test environment.
Steps to reproduce:
{
"name": "Python: Debug Tests",
// "type": "python", // Works when type is set to python
"type": "debugpy",
"request": "launch",
"program": "${file}",
"purpose": [
"debug-test"
],
"env": {
"PYTEST_ADDOPTS": "--no-cov"
},
"console": "integratedTerminal",
"justMyCode": true
},
Diagnostic data
python.languageServer
setting: DefaultOutput for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)User Settings
Extension version: 2023.25.10292213
VS Code version: Code - Insiders 1.86.0-insider (05047486b6df5eb8d44b2ecd70ea3bdf775fd937, 2024-01-31T03:29:26.801Z)
OS version: Linux x64 6.5.0-15-generic snap
Modes:
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: