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 discovery error with "]" char in pytest.mark.parametrize #17750

Closed
RoPP opened this issue Oct 15, 2021 · 1 comment
Closed

Pytest discovery error with "]" char in pytest.mark.parametrize #17750

RoPP opened this issue Oct 15, 2021 · 1 comment
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@RoPP
Copy link

RoPP commented Oct 15, 2021

Environment data

  • VS Code version: 1.61.1
  • Extension version (available under the Extensions sidebar): v2021.10.1336267007
  • OS and version: Linux
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Relevant/affected Python packages and their versions: XXX
  • Relevant/affected Python-related VS Code extensions and their versions: XXX
  • Value of the python.languageServer setting: pylance

[NOTE: If you suspect that your issue is related to the Microsoft Python Language Server (python.languageServer: 'Microsoft'), please download our new language server Pylance from the VS Code marketplace to see if that fixes your issue]

Expected behaviour

List tests in test explorer

Actual behaviour

image

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. write a pytest
import pytest

@pytest.mark.parametrize("foo", (chr(93),))
def test_foo(self, foo):
  assert True

Peek 14-10-2021 11-56

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

> ~/.virtualenvs/bug_vscode/bin/python ~/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/Code/xxx/bug_pytest_vscode -s --cache-clear
cwd: ~/Code/xxx/bug_pytest_vscode
Error 2021-10-15 13:44:06: Error discovering pytest tests:
 r [Error]: ============================= test session starts ==============================
platform linux -- Python 3.9.5, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /home/yyy/Code/xxx/bug_pytest_vscode
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: ./tests/test_plop.py::test_foo[]]

traceback:
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/run_adapter.py", line 22, in <module>
    main(tool, cmd, subargs, toolargs)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/__main__.py", line 100, in main
    parents, result = run(toolargs, **subargs)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 30, in discover
    ec = _pytest_main(pytestargs, [_plugin])
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/config/__init__.py", line 162, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 316, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 269, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 322, in _main
    config.hook.pytest_collection(session=session)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 333, in pytest_collection
    session.perform_collect()
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 637, in perform_collect
    hook.pytest_collection_modifyitems(
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 92, in pytest_collection_modifyitems
    test, parents = self.parse_item(item)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 77, in parse_item
    return parse_item(item)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 161, in parse_item
    (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 144, in <lambda>
    _parse_node_id=(lambda *a: _parse_node_id(*a)),
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 382, in _parse_node_id
    testid, name, kind = next(nodes)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 479, in _iter_nodes
    raise should_never_reach_here(
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 132, in should_never_reach_here
    traceback.print_stack()
collected 1 item

<Module tests/test_plop.py>
  <Function test_foo[]]>
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: ./tests/test_plop.py::test_foo[]]

traceback:
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/run_adapter.py", line 22, in <module>
    main(tool, cmd, subargs, toolargs)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/__main__.py", line 100, in main
    parents, result = run(toolargs, **subargs)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 30, in discover
    ec = _pytest_main(pytestargs, [_plugin])
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/config/__init__.py", line 162, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 316, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 269, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 322, in _main
    config.hook.pytest_collection(session=session)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 333, in pytest_collection
    session.perform_collect()
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 641, in perform_collect
    hook.pytest_collection_finish(session=self)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 107, in pytest_collection_finish
    test, parents = self.parse_item(item)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 77, in parse_item
    return parse_item(item)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 161, in parse_item
    (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 144, in <lambda>
    _parse_node_id=(lambda *a: _parse_node_id(*a)),
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 382, in _parse_node_id
    testid, name, kind = next(nodes)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 479, in _iter_nodes
    raise should_never_reach_here(
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/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 "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 637, in perform_collect
INTERNALERROR>     hook.pytest_collection_modifyitems(
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 92, in pytest_collection_modifyitems
INTERNALERROR>     test, parents = self.parse_item(item)
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 77, in parse_item
INTERNALERROR>     return parse_item(item)
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 161, in parse_item
INTERNALERROR>     (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 144, in <lambda>
INTERNALERROR>     _parse_node_id=(lambda *a: _parse_node_id(*a)),
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 382, in _parse_node_id
INTERNALERROR>     testid, name, kind = next(nodes)
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/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 "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 322, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 333, in pytest_collection
INTERNALERROR>     session.perform_collect()
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/_pytest/main.py", line 641, in perform_collect
INTERNALERROR>     hook.pytest_collection_finish(session=self)
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/yyy/.virtualenvs/bug_vscode/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 107, in pytest_collection_finish
INTERNALERROR>     test, parents = self.parse_item(item)
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 77, in parse_item
INTERNALERROR>     return parse_item(item)
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 161, in parse_item
INTERNALERROR>     (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 144, in <lambda>
INTERNALERROR>     _parse_node_id=(lambda *a: _parse_node_id(*a)),
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 382, in _parse_node_id
INTERNALERROR>     testid, name, kind = next(nodes)
INTERNALERROR>   File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/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.01s ===========================

Traceback (most recent call last):
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/run_adapter.py", line 22, in <module>
    main(tool, cmd, subargs, toolargs)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/testing_tools/adapter/__main__.py", line 100, in main
    parents, result = run(toolargs, **subargs)
  File "/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/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> (/home/yyy/.vscode/extensions/ms-python.python-2021.10.1336267007/out/client/extension.js:17:37534)
    at Object.onceWrapper (events.js:422:26)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Socket.<anonymous> (internal/child_process.js:439:11)
    at Socket.emit (events.js:315:20)
    at Pipe.<anonymous> (net.js:673:12)

@RoPP RoPP added bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Oct 15, 2021
@karthiknadig
Copy link
Member

Duplicate of #17676

@karthiknadig karthiknadig marked this as a duplicate of #17676 Oct 15, 2021
@karthiknadig karthiknadig removed the triage-needed Needs assignment to the proper sub-team label Oct 18, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants