Pytest node issue during test discovery
See original GitHub issueIssue 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.languageServer
setting: 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® Core™ 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® Core™ 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
Issue Analytics
- State:
- Created a year ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
VSCode pytest test discovery fails - python - Stack Overflow
In my case the problem with vscode being unable to discover tests was the coverage module being enabled in the setup ...
Read more >Changelog — pytest documentation
Bug Fixes¶. #10060: When running with --pdb , TestCase.tearDown is no longer called for tests when the class has been skipped via unittest.skip...
Read more >pytest Documentation - Read the Docs
How to use temporary directories and files in tests . ... More generally, pytest follows standard test discovery rules.
Read more >schrodinger.test.pytest_customizations module - Schrödinger
Still leaves us vulnerable to incorrect caching during test discovery, though. See https://github.com/pytest-dev/pytest/issues/2016.
Read more >unittest — Unit testing framework — Python 3.11.1 ...
pytest. Third-party unittest framework with a lighter-weight syntax for writing ... Test discovery is implemented in TestLoader.discover() , but can also be ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Mirandatz We have a fix for the crash. It should be in the next pre-release tomorrow.
I was unable to run that command:
But adapting it to use
.vscode-server
instead of.vscode
andms-python.python-2022.10.1
instead ofms-python.python-2022.10.0
result in: