Repository navigation
pytest arg parsing bug #21176
Copy link
Copy link
Open
Labels
area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugneeds spikeLabel for issues that need investigation before they can be worked on.Label for issues that need investigation before they can be worked on.
Description
Type: Bug
Behaviour
Expected vs. Actual
Running a pytest test with pytestArgs results in the error
Error while running tests: test_example
TypeError: Cannot read properties of null (reading 'testsuites')
After removing the pytestArgs from the settings.json, everything runs as expected.
Steps to reproduce:
- Open a project with a pytest (i.e. https://github.com/philippun1/pytest-vscode-parameters which I created specifically to reproduce this bug)
- Let VS Code create a settings.json (or use the one from my repo)
- Add pytestArgs (or use the one from my repo), i.e.
"python.testing.pytestArgs": [
".",
"--test_option",
"somevalue"
],
- Go to the testing tab and run the test
- Test Results tab shows the type error
- Run from the terminal instead gives no error:
pytest . --test_option somevalue
Diagnostic data
This test report was made on an Ubuntu machine, but can also be reproduced on a Windows system with the latest VS Code and python extension.
- Python version (& distribution if applicable, e.g. Anaconda): 3.11.2
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Global
- Value of the
python.languageServersetting: Default
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
[output is empty]
User Settings
languageServer: "Pylance"
testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true
Extension version: 2023.6.1
VS Code version: Code 1.77.3 (704ed70d4fd1c6bd6342c436f1ede30d1cff4710, 2023-04-12T09:16:52.732Z)
OS version: Linux x64 6.2.0-20-generic
Modes:
Sandboxed: Yes
System Info
| Item | Value |
|---|---|
| CPUs | Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz (8 x 2804) |
| 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 opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_renderer: enabled_on video_decode: disabled_software video_encode: disabled_software vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: disabled_off |
| Load (avg) | 1, 1, 1 |
| Memory (System) | 15.35GB (8.29GB free) |
| Process Argv | --unity-launch --crash-reporter-id 2d6dab3d-7a47-4211-935d-970af4709a92 |
| Screen Reader | no |
| VM | 0% |
| DESKTOP_SESSION | ubuntu |
| XDG_CURRENT_DESKTOP | Unity |
| XDG_SESSION_DESKTOP | ubuntu |
| XDG_SESSION_TYPE | wayland |
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscorecescf:30445987
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
3biah626:30602489
pyind779:30671433
f6dab269:30613381
vscrpc:30673769
pythonsymbol12:30671437
6233i204:30730053
vsctsb:30705553
azdwalk:30721579
pythonms35:30701012
pythonfmttextcf:30716743
pythonclientmvcf:30725893
fixshowwlkth:30730052
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugneeds spikeLabel for issues that need investigation before they can be worked on.Label for issues that need investigation before they can be worked on.
Activity
eleanorjboyd commentedon May 4, 2023
Hi! Yes I am able to replicate what you are seeing. It seems like the extension is trying to run
./.venv/bin/python -m pytest --rootdir . --override-ini junit_family=xunit1 --junit-xml=/var/folders/q8/17wzg0cx7p59c1qfvwxx8yhc0000gn/T/tmp-852821jmb8LyMYWVJ.xml --test_optionwhich does not correctly include the"somevalue"parameter. This is likely due to the parsing we have on our current test design which is buggy. We are in the process of doing a testing rewrite which you can follow along with here. It is almost ready for release and I have already tested it with your use case and it works successfully. Please subscribe to the issue for updates and we will hopefully have more information soon!eleanorjboyd commentedon Jul 7, 2023
Hello! We have just finished our testing rewrite and are beginning the roll out to users. If you are able, it would be very helpful to know if your issue still exists on the rewrite! To try it yourself, you need to be on the most recent release of the Python extension and add this setting to your users
settings.json"python.experiments.optInto": ["pythonTestAdapter"]. Let me know if the rewrite fixes your issue. Thanks!philippun1 commentedon Jul 7, 2023
It appears there is no difference if I add the
pythonTestAdaptersetting or not. Tested both with the latest Python Plugin release (v2023.12.0) and preview release (v2023.13.11881007) with VS Code 1.80.0Can I somehow verify if the new test adapter is being used?
I updated my test repo with the
pythonTestAdaptersetting and also some updates to the test itself to make analyzing easier.eleanorjboyd commentedon Jul 7, 2023
Hi! You can see if it is enabled for you by setting
"python.analysis.logLevel": "Trace",in your user settings then check for2023-07-05 16:06:27.767 [info] Experiment 'pythonTestAdapter' is activein your python logs. If that message is printed then the rewrite is enabled. I will try and repro this later but if you send over your python logs then I might be able to diagnose it quicker. Thanks for your help!!philippun1 commentedon Jul 7, 2023
This is my python log if I run the test in the Testing tab:
And this if I just run the discovery with the Refresh Tests button:
The log does not change if I set or unset the logLevel to Trace. It feels like the settings are not applied at all?
But we can see that the
--test_option asdis added properly on discovery, but not for the real test.eleanorjboyd commentedon Jul 7, 2023
hm yes I can see from
2023-07-07 22:42:58.808 [info] > /usr/bin/python -m pytest -p vscode_pytest --collect-only . --test_option asdit is running the new code, maybe it didn't print that it was on the setting since that log is set on startup of the extension. Either way it is running the new stuff. Thanks for checking I will look into this more!!philippun1 commentedon Jul 22, 2023
There is a workaround for this issue if I use the parameter like this:

At least it is usable now, but it would be great if the arguments would work in the same way as for pytest:
pytest --test_option asdandpytest --test_option=asdboth work if I call it directly from a terminal.eleanorjboyd commentedon Aug 11, 2023
Hi! Sorry haven't followed up on this in a minute. On further investigation, this is related to a larger issue around settings which the team will be discussing soon. I will update with information after that.
eleanorjboyd commentedon Aug 18, 2023
I created a proposal with a solution for this problem, would love your input on the above issue! #21845
melMass commentedon Sep 3, 2023
I'm not 100% sure it's related but the same happens when using
pytest-timeout:nsheaps commentedon Sep 20, 2023
Hi all, actually just posted in #22032 about a similar issue and just want to call out that I have args, but when I have
-n 8(part of pytest-xdist for distributing across cpu cores) I can't debug the tests with that error. Just removing the flags works fine and I can debug the tests.Pytest-xdist explicitly says
--pdbis disabled when distributing tests in the docseleanorjboyd commentedon Oct 6, 2023
Nathan Heaps (@nsheaps) thank you for your contribution! We will keep this in mind as we work through the proposal!
[-]Adding pytestArgs gives TypeError: Cannot read properties of null (reading 'testsuites')[/-][+]pytest arg parsing bug[/+]schwaerz commentedon Jul 8, 2024
I am getting this error on a very simple pytest project. Cannot get debugging to work.
It does not matter for me whether I use
pytestArgsor not. Will always get the same error when trying to debug a test:Not sure what's going on.
Just tried in another project. Same error there :(
This used to work, as there has been some time while I did not do any python development I cannot say at what time it stopped working.
eleanorjboyd commentedon Jul 9, 2024
hm interesting- could you open an new bug report since this is likely a different problem? Primarily I would need logs from the python output channel but if you use the report issue command on vscode it will gather all this info for you. Thanks!
schwaerz commentedon Jul 9, 2024
Ok, will do that, thanks.
schwaerz commentedon Jul 9, 2024
For reference: #23776