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 fail to discover test case when the python string contain unmatched parenthess #17866

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

Comments

@liaoya
Copy link

liaoya commented Oct 28, 2021

Environment data

  • VS Code version: 1.61.2
  • Extension version (available under the Extensions sidebar): v2021.10.1365161279
  • OS and version: Windows 10 21H1
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.10.0
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv
  • Value of the python.languageServer setting: Pylance v2021.10.3

Expected behaviour

Can discover python test case

Actual behaviour

Fail to discover python test case

Steps to reproduce:

The python code validparentheses.py

class ReplaceSolution:
    def isValid(self, s: str) -> bool:
        length = len(s)
        while True:
            s = s.replace("()", "").replace("{}", "").replace("[]", "")
            if len(s) == length:
                break
            length = len(s)
        return not s

The test code

import pytest

from validparentheses import ReplaceSolution

@pytest.mark.parametrize("s,expect", [("()", True), ("()[]{}", True), ("(]", False), ("([)]", False), ("{[]}", True)])
def test_validparentheses(s: str, expect: bool):
    assert ReplaceSolution().isValid(s) == expect

Logs

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: ./problem/20/test_validparentheses.py::test_validparentheses[(]-False]

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

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

Duplicate of #17676

@karthiknadig karthiknadig marked this as a duplicate of #17676 Oct 28, 2021
@karthiknadig karthiknadig removed the triage-needed Needs assignment to the proper sub-team label Oct 28, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 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