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

Pytest test discovery fails when testcase name does not contain matching numbers of open and closed brackets #17954

Closed
1 task done
scwilbanks opened this issue Nov 7, 2021 · 1 comment
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug

Comments

@scwilbanks
Copy link

VS Code version

1.62.0

Extension version

v2021.11.1422169775

OS type

Windows

OS version

Version 10.0.19043 Build 19043

Python distribution

Anaconda

Python version

3.8.12

Language server

Pylance

Expected behaviour

The test discover feature in the test explorer (using pythonFiles\testing_tools\run_adapter.py) should not fail in cases where pytest does not. If you have a pytest testing function with a parameterized name that does not contain equal numbers of open and close brackets, test discovery fails, but it should not as running pytest in the terminal will pass.

Actual behaviour

Test discovery fails with a NotImplementedError: Unexpected pytest node due to the logic in pythonFiles\testing_tools\adapter\pytest_pytest_item.py _find_left_bracket assuming matching numbers of open and closed brackets.

Steps to reproduce

import pandas as pd
import pytest

@pytest.mark.parametrize("interval, expected", [(pd.Interval(0, 1), True)], ids=str)
def test_error(interval, expected):
assert True

Logs

~\anaconda3\python.exe ~.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir ~\source\repos\vscode_error -s --cache-clear .
cwd: ~\source\repos\vscode_error
Error 2021-11-07 10:30:31: Error discovering pytest tests:
[r [Error]: ============================= test session starts =============================
platform win32 -- Python 3.8.8, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: c:\Users\scwil\source\repos\vscode_error
plugins: anyio-2.2.0, hypothesis-6.24.2
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: ./test_error.py::test_error[(0, 1]-True]

traceback:
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\run_adapter.py", line 22, in
main(tool, cmd, subargs, toolargs)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter_main_.py", line 100, in main
parents, result = run(toolargs, **subargs)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 30, in discover
ec = _pytest_main(pytestargs, [plugin])
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\config_init
.py", line 162, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\hooks.py", line 286, in call
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 84, in
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 316, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 269, in wrap_session
session.exitstatus = doit(config, session) or 0
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 322, in _main
config.hook.pytest_collection(session=session)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\hooks.py", line 286, in call
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 84, in
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 333, in pytest_collection
session.perform_collect()
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 637, in perform_collect
hook.pytest_collection_modifyitems(
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\hooks.py", line 286, in call
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 84, in
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 92, in pytest_collection_modifyitems
test, parents = self.parse_item(item)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 77, in parse_item
return parse_item(item)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 161, in parse_item
(nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 144, in
_parse_node_id=(lambda *a: _parse_node_id(*a)),
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 382, in _parse_node_id
testid, name, kind = next(nodes)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 479, in _iter_nodes
raise should_never_reach_here(
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 132, in should_never_reach_here
traceback.print_stack()
collected 1 item

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: ./test_error.py::test_error[(0, 1]-True]

traceback:
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\run_adapter.py", line 22, in
main(tool, cmd, subargs, toolargs)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter_main_.py", line 100, in main
parents, result = run(toolargs, **subargs)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 30, in discover
ec = _pytest_main(pytestargs, [plugin])
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\config_init
.py", line 162, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\hooks.py", line 286, in call
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 84, in
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 316, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 269, in wrap_session
session.exitstatus = doit(config, session) or 0
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 322, in _main
config.hook.pytest_collection(session=session)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\hooks.py", line 286, in call
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 84, in
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 333, in pytest_collection
session.perform_collect()
File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 641, in perform_collect
hook.pytest_collection_finish(session=self)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\hooks.py", line 286, in call
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 84, in
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 107, in pytest_collection_finish
test, parents = self.parse_item(item)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 77, in parse_item
return parse_item(item)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 161, in parse_item
(nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 144, in
_parse_node_id=(lambda *a: _parse_node_id(*a)),
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 382, in _parse_node_id
testid, name, kind = next(nodes)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 479, in _iter_nodes
raise should_never_reach_here(
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\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 "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 637, in perform_collect
INTERNALERROR> hook.pytest_collection_modifyitems(
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\hooks.py", line 286, in call
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 84, in
INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 92, in pytest_collection_modifyitems
INTERNALERROR> test, parents = self.parse_item(item)
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 77, in parse_item
INTERNALERROR> return parse_item(item)
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 161, in parse_item
INTERNALERROR> (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 144, in
INTERNALERROR> _parse_node_id=(lambda *a: _parse_node_id(*a)),
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 382, in _parse_node_id
INTERNALERROR> testid, name, kind = next(nodes)
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 479, in _iter_nodes
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 "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 269, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 322, in _main
INTERNALERROR> config.hook.pytest_collection(session=session)
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\hooks.py", line 286, in call
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 84, in
INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 333, in pytest_collection
INTERNALERROR> session.perform_collect()
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages_pytest\main.py", line 641, in perform_collect
INTERNALERROR> hook.pytest_collection_finish(session=self)
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\hooks.py", line 286, in call
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\manager.py", line 84, in
INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "C:\Users\scwil\anaconda3\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 107, in pytest_collection_finish
INTERNALERROR> test, parents = self.parse_item(item)
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_discovery.py", line 77, in parse_item
INTERNALERROR> return parse_item(item)
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 161, in parse_item
INTERNALERROR> (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 144, in
INTERNALERROR> _parse_node_id=(lambda *a: _parse_node_id(*a)),
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 382, in _parse_node_id
INTERNALERROR> testid, name, kind = next(nodes)
INTERNALERROR> File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter\pytest_pytest_item.py", line 479, in _iter_nodes
INTERNALERROR> raise should_never_reach_here(
INTERNALERROR> NotImplementedError: Unexpected pytest node (see printed output).

========================== 1 test collected in 0.66s ==========================

Traceback (most recent call last):
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\run_adapter.py", line 22, in
main(tool, cmd, subargs, toolargs)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\testing_tools\adapter_main_.py", line 100, in main
parents, result = run(toolargs, **subargs)
File "c:\Users\scwil.vscode\extensions\ms-python.python-2021.11.1422169775\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> (c:\Users\scwil\.vscode\extensions\ms-python.python-2021.11.1422169775\out\client\extension.js:17:38446)
at Object.onceWrapper (events.js:422:26)
at ChildProcess.emit (events.js:315:20)
at maybeClose (internal/child_process.js:1048:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)]

Code of Conduct

  • I agree to follow this project's Code of Conduct
@scwilbanks scwilbanks added bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Nov 7, 2021
@karthiknadig karthiknadig self-assigned this Nov 8, 2021
@karthiknadig karthiknadig added area-testing triage and removed triage-needed Needs assignment to the proper sub-team labels Nov 8, 2021
@karthiknadig
Copy link
Member

Duplicate of #17676

@karthiknadig karthiknadig marked this as a duplicate of #17676 Nov 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants