Repository navigation
Pytest node issue during test discovery #19334
Copy link
Copy link
Closed
Labels
area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug
Description
Issue Type: Bug
Behaviour
Expected vs. Actual
Expected: test discovery works.
Actual: does not.
Steps to reproduce:
Click "Refresh tests" button.
Diagnostic data
- Python version (& distribution if applicable, e.g. Anaconda): 3.10.4
- 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)
> /bin/python ~/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear gge
cwd: .
[ERROR 2022-5-20 14:2:2.230]: Error discovering pytest tests:
[n [Error]: ============================= test session starts ==============================
platform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0
cachedir: /dev/shm/pytest_cache
rootdir: /workspaces/gge, configfile: pyproject.toml
plugins: hypothesis-6.46.11, typeguard-2.13.3, pspec-0.0.4, xdist-2.5.0, forked-1.4.0
The Python extension has run into an unexpected situation
while processing a pytest node during test discovery. Please
Please open an issue at:
https://github.com/microsoft/vscode-python/issues
and paste the following output there.
nodeid: gge/tests/test_simplest.py::::test_halp
kind: ('function', False)
class: Function
name: test_halp
fspath: /workspaces/gge/gge/tests/test_simplest.py
location: ('gge/tests/test_simplest.py', 0, 'test_halp')
function: <function test_halp at 0x7f27365b4c10>
markers: []
user_properties: []
attrnames: ['_ALLOW_MARKERS', '__annotations__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__weakref__', '_check_item_and_collector_diamond_inheritance', '_fixtureinfo', '_getobj', '_initrequest', '_nodeid', '_obj', '_prunetraceback', '_pyfuncitem', '_pytest_diamond_inheritance_warning_shown', '_report_sections', '_repr_failure_py', '_request', '_store', 'add_marker', 'add_report_section', 'addfinalizer', 'cls', 'config', 'extra_keyword_matches', 'fixturenames', 'from_parent', 'fspath', 'funcargs', 'function', 'get_closest_marker', 'getmodpath', 'getparent', 'ihook', 'instance', 'iter_markers', 'iter_markers_with_node', 'keywords', 'listchain', 'listextrakeywords', 'listnames', 'location', 'module', 'name', 'nextitem', 'nodeid', 'obj', 'originalname', 'own_markers', 'parent', 'path', 'reportinfo', 'repr_failure', 'runtest', 'session', 'setup', 'stash', 'teardown', 'user_properties', 'warn']
extra info:
fullname: test_halp
testfunc: .test_halp
parameterized:
traceback:
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/run_adapter.py", line 22, in <module>
main(tool, cmd, subargs, toolargs)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/__main__.py", line 100, in main
parents, result = run(toolargs, **subargs)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 30, in discover
ec = _pytest_main(pytestargs, [_plugin])
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 164, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 315, in pytest_cmdline_main
return wrap_session(config, _main)
File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 268, in wrap_session
session.exitstatus = doit(config, session) or 0
File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 321, in _main
config.hook.pytest_collection(session=session)
File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 332, in pytest_collection
session.perform_collect()
File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 660, in perform_collect
hook.pytest_collection_modifyitems(
File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 92, in pytest_collection_modifyitems
test, parents = self.parse_item(item)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 77, in parse_item
return parse_item(item)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 184, in parse_item
raise should_never_reach_here(
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 132, in should_never_reach_here
traceback.print_stack()
collected 1 item
<Package tests>
<Module test_simplest.py>
<Function test_halp>
The Python extension has run into an unexpected situation
while processing a pytest node during test discovery. Please
Please open an issue at:
https://github.com/microsoft/vscode-python/issues
and paste the following output there.
nodeid: gge/tests/test_simplest.py::::test_halp
kind: ('function', False)
class: Function
name: test_halp
fspath: /workspaces/gge/gge/tests/test_simplest.py
location: ('gge/tests/test_simplest.py', 0, 'test_halp')
function: <function test_halp at 0x7f27365b4c10>
markers: []
user_properties: []
attrnames: ['_ALLOW_MARKERS', '__annotations__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__weakref__', '_check_item_and_collector_diamond_inheritance', '_fixtureinfo', '_getobj', '_initrequest', '_nodeid', '_obj', '_prunetraceback', '_pyfuncitem', '_pytest_diamond_inheritance_warning_shown', '_report_sections', '_repr_failure_py', '_request', '_store', 'add_marker', 'add_report_section', 'addfinalizer', 'cls', 'config', 'extra_keyword_matches', 'fixturenames', 'from_parent', 'fspath', 'funcargs', 'function', 'get_closest_marker', 'getmodpath', 'getparent', 'ihook', 'instance', 'iter_markers', 'iter_markers_with_node', 'keywords', 'listchain', 'listextrakeywords', 'listnames', 'location', 'module', 'name', 'nextitem', 'nodeid', 'obj', 'originalname', 'own_markers', 'parent', 'path', 'reportinfo', 'repr_failure', 'runtest', 'session', 'setup', 'stash', 'teardown', 'user_properties', 'warn']
extra info:
fullname: test_halp
testfunc: .test_halp
parameterized:
traceback:
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/run_adapter.py", line 22, in <module>
main(tool, cmd, subargs, toolargs)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/__main__.py", line 100, in main
parents, result = run(toolargs, **subargs)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 30, in discover
ec = _pytest_main(pytestargs, [_plugin])
File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 164, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 315, in pytest_cmdline_main
return wrap_session(config, _main)
File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 268, in wrap_session
session.exitstatus = doit(config, session) or 0
File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 321, in _main
config.hook.pytest_collection(session=session)
File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 332, in pytest_collection
session.perform_collect()
File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 664, in perform_collect
hook.pytest_collection_finish(session=self)
File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 107, in pytest_collection_finish
test, parents = self.parse_item(item)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 77, in parse_item
return parse_item(item)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 184, in parse_item
raise should_never_reach_here(
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 132, in should_never_reach_here
traceback.print_stack()
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 660, in perform_collect
INTERNALERROR> hook.pytest_collection_modifyitems(
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 92, in pytest_collection_modifyitems
INTERNALERROR> test, parents = self.parse_item(item)
INTERNALERROR> File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 77, in parse_item
INTERNALERROR> return parse_item(item)
INTERNALERROR> File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 184, in parse_item
INTERNALERROR> raise should_never_reach_here(
INTERNALERROR> NotImplementedError: Unexpected pytest node (see printed output).
INTERNALERROR>
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 268, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 321, in _main
INTERNALERROR> config.hook.pytest_collection(session=session)
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 332, in pytest_collection
INTERNALERROR> session.perform_collect()
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 664, in perform_collect
INTERNALERROR> hook.pytest_collection_finish(session=self)
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 107, in pytest_collection_finish
INTERNALERROR> test, parents = self.parse_item(item)
INTERNALERROR> File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 77, in parse_item
INTERNALERROR> return parse_item(item)
INTERNALERROR> File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 184, in parse_item
INTERNALERROR> raise should_never_reach_here(
INTERNALERROR> NotImplementedError: Unexpected pytest node (see printed output).
========================== 1 test collected in 0.02s ===========================
Traceback (most recent call last):
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/run_adapter.py", line 22, in <module>
main(tool, cmd, subargs, toolargs)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/__main__.py", line 100, in main
parents, result = run(toolargs, **subargs)
File "/root/.vscode-server/extensions/ms-python.python-2022.8.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 44, in discover
raise Exception("pytest discovery failed (exit code {})".format(ec))
Exception: pytest discovery failed (exit code 3)
at ChildProcess.<anonymous> (/root/.vscode-server/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 Socket.<anonymous> (node:internal/child_process:450:11)
at Socket.emit (node:events:390:28)
at Pipe.<anonymous> (node:net:687:12)]
User Settings
languageServer: "Jedi"
linting
• flake8Enabled: true
• mypyArgs: "<placeholder>"
• mypyEnabled: true
sortImports
• args: "<placeholder>"
formatting
• provider: "black"
testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true
Extension version: 2022.8.0
VS Code version: Code 1.68.1 (30d9c6cd9483b2cc586687151bcbcd635f373630, 2022-06-15T02:58:26.441Z)
OS version: Linux x64 5.15.0-33-generic
Restricted Mode: No
Remote OS version: Linux x64 5.15.0-33-generic
System Info
| Item | Value |
|---|---|
| CPUs | Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz (12 x 2600) |
| 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: disabled_off opengl: enabled_on rasterization: disabled_software raw_draw: disabled_off_ok skia_renderer: enabled_on video_decode: disabled_software video_encode: disabled_software vulkan: disabled_off webgl: enabled webgl2: enabled |
| Load (avg) | 1, 2, 2 |
| Memory (System) | 15.50GB (5.25GB free) |
| Process Argv | --unity-launch --crash-reporter-id 2fd4e909-5d7a-4dd6-8163-dcde3e1c3c92 |
| Screen Reader | no |
| VM | 0% |
| DESKTOP_SESSION | cinnamon |
| XDG_CURRENT_DESKTOP | X-Cinnamon |
| XDG_SESSION_DESKTOP | cinnamon |
| XDG_SESSION_TYPE | x11 |
| Item | Value |
|---|---|
| Remote | Dev Container |
| OS | Linux x64 5.15.0-33-generic |
| CPUs | Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz (12 x 4208) |
| Memory (System) | 15.50GB (5.25GB free) |
| VM | 0% |
Extra info: I have a single test file:

With the following code:
def test_halp() -> None:
assert 2 == 2
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 bug
Activity
karthiknadig commentedon Jun 21, 2022
The node id
gge/tests/test_simplest.py::::test_halplooks weird. Can you runpytest --collect-onlyand share the output?Mirandatz commentedon Jun 21, 2022
Output of
pytest --collect-onlyMirandatz commentedon Jun 21, 2022
And output of
pytestkarthiknadig commentedon Jun 21, 2022
Mirandatz (@Mirandatz) Can you run pytest with
-vso I can see the individual test ids?Mirandatz commentedon Jun 21, 2022
karthiknadig commentedon Jun 24, 2022
Mirandatz (@Mirandatz) We have a fix for the crash. It should be in the next pre-release tomorrow.
Mirandatz commentedon Jul 12, 2022
I updated VS Code to 1.69.1, but now this happens:
Should I create a new issue? Is this related?
Obs: invoking pytest from the builtin terminal still works:
karthiknadig commentedon Jul 12, 2022
This is a known issue with how id's are handled when using plugins like hypothesis. We have a separate issue tracking ptyest issue with plugins, we have plans to address this with a new test adapter for pytest #16852
karthiknadig commentedon Jul 12, 2022
Mirandatz (@Mirandatz) When you run tests it generates a xml file with test results, would it be possible to find it and share the contents from it? You should be able to see the path in the output logs.
Mirandatz commentedon Jul 13, 2022
I can't find this .xml, where is it stored by default?
karthiknadig commentedon Jul 15, 2022
It is stored in the /tmp directory somewhere. You have to look the Output > python log, it will show you the exact path:
Mirandatz commentedon Jul 15, 2022
The log output shows
But when I try to cp the file tmp-261pkSEVvxk0FhS.xml is errors out:
I think this file is automatically deleted? Or may it is not generate at all? I don't know.
When I executed the command manually (instead of relying on VS Code) the .xml file contents were:
karthiknadig commentedon Jul 15, 2022
Mirandatz (@Mirandatz) it gets created as a temp file, I guess it is getting cleaned up when the process exits. Thanks for running it manually. One more favor, can you run the discovery script also manually. Both together should pinpoint the problem. Make sure the script path is correct for your machine.
Mirandatz commentedon Jul 16, 2022
I was unable to run that command:
But adapting it to use
.vscode-serverinstead of.vscodeandms-python.python-2022.10.1instead ofms-python.python-2022.10.0result in: