Repository navigation
should_never_reach_here for particular test case when parametrized test has unmatched brackets or parenthesis #17676
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from posterIssue requires more information from poster
Description
Environment data
- VS Code version: 1.62.0-insider
- Extension version (available under the Extensions sidebar): Python v2021.10.1317843341
- OS and version: Windows_NT x64 10.0.19043
- Python version (& distribution if applicable, e.g. Anaconda): 3.8.0
- Type of virtual environment used: N/A
- Value of the
python.languageServersetting: Pylance
Expected behaviour
Non-fatal test discovery.
Actual behaviour
Runtime error causes test discovery to fail.
Steps to reproduce:
@pytest.mark.parametrize("test_input,expected",
[
# Some tests,
("spaces](www", "spaces](www"),
# Some other tests,
]
)
def test_remove_markdown_links(test_input, expected):
# My implementationCommenting out the above test case removes the symptoms of the bug.
Logs
Details
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: ./deployment/tests/test_text_helper.py::test_remove_markdown_links[spaces](www-spaces](www]
traceback:
File "/home/eric/.vscode-server/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/run_adapter.py", line 22, in <module>
main(tool, cmd, subargs, toolargs)
File "/home/eric/.vscode-server/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/adapter/__main__.py", line 100, in main
parents, result = run(toolargs, **subargs)
File "/home/eric/.vscode-server/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 30, in discover
ec = _pytest_main(pytestargs, [_plugin])
File "/home/eric/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 162, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/home/eric/.local/lib/python3.8/site-packages/_pytest/main.py", line 316, in pytest_cmdline_main
return wrap_session(config, _main)
File "/home/eric/.local/lib/python3.8/site-packages/_pytest/main.py", line 269, in wrap_session
session.exitstatus = doit(config, session) or 0
File "/home/eric/.local/lib/python3.8/site-packages/_pytest/main.py", line 322, in _main
config.hook.pytest_collection(session=session)
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/home/eric/.local/lib/python3.8/site-packages/_pytest/main.py", line 333, in pytest_collection
session.perform_collect()
File "/home/eric/.local/lib/python3.8/site-packages/_pytest/main.py", line 641, in perform_collect
hook.pytest_collection_finish(session=self)
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "/home/eric/.local/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/home/eric/.vscode-server/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 107, in pytest_collection_finish
test, parents = self.parse_item(item)
File "/home/eric/.vscode-server/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 77, in parse_item
return parse_item(item)
File "/home/eric/.vscode-server/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 161, in parse_item
(nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
File "/home/eric/.vscode-server/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 144, in <lambda>
_parse_node_id=(lambda *a: _parse_node_id(*a)),
File "/home/eric/.vscode-server/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 382, in _parse_node_id
testid, name, kind = next(nodes)
File "/home/eric/.vscode-server/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 479, in _iter_nodes
raise should_never_reach_here(
File "/home/eric/.vscode-server/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 132, in should_never_reach_here
traceback.print_stack()
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 buginfo-neededIssue requires more information from posterIssue requires more information from poster
Activity
SteggyLeggy commentedon Oct 11, 2021
Same issue here, just started happening for me with an existing project using this parametrize decorator.
Have recreated in a new folder, using a much simpler test case
Like I said test discovery was working last week, and I haven't updated pytest since then. Looking at the code in
_find_left_bracketin_pytest_item.pyit looks like it would of never been able to handle a parameter that contains a single]so I've no idea why it suddenly stopped work (or how it was working ok before).EDIT:
Just downgraded to version
2021.9.1246542782of ms-python.python (I had to download the vsix file and install via the command line) but that has fixed the issue so far.mjpieters commentedon Oct 13, 2021
The relevant commit is a68f98f, which is PR #17357.
mjpieters commentedon Oct 13, 2021
This unfortunately caused a lot of breakage in projects that have an 'unbalanced'
]character in a parameter. The assumption that brackets are always balanced is not correct here, I fear!Instead, shouldn't the code not just use the provided Node and Function interfaces to 'parse' the name? I know that currently
_parse_node_id()is not passed the original item, onlyitem.nodeid, butitemhas enough information to avoid this whole issue.E.g., given:
then when I inspect
iteminsidetesting_tools/adapter/pytest/_pytest_item.py:parse_item()you can see it has all the information that_parse_node_id()tries to extract as rich Python object data:I also note that there is also a helpful
_pytest.nodes.iterparentnodeids()function:If the expected output for
_iter_nodesis:then using
.nodeidalone is going to make this way, way too hard. Instead, the first 2 values can already nicely approximated with:Then, perhaps use
item.iterchain()[0].fspathas the basis for constructing the remaining elements from theitem.fspath.parts()list (see thepy.pathdocumentation for theLocalPath()class API).mjpieters commentedon Oct 13, 2021
I fixed this locally by replacing lines 161-163 in testing_tools/adapter/pytest/_pytest_item.py, with:
On your local system, that's
~/.vscode/extensions/ms-python.python-2021.10.1317843341/pythonFiles/testing_tools/adapter/pytest/_pytest_item.pySo, if the current item is a function and has been parametrized (sic, pytest's misspelling), then it parses the item without the parameters, to then add back that information based on the parsed result. This avoids having to fully rework the way the rest of the nodeid elements are parsed and normalized.
karthiknadig commentedon Oct 13, 2021
Martijn Pieters (@mjpieters) Can you make a PR with this change?
mjpieters commentedon Oct 13, 2021
I was thinking of that change as an ugly-ish work-around, not the full solution, to be honest.
I'd be happy to turn it into a PR of course, it's your tech debt to pay later ;-)
karthiknadig commentedon Oct 18, 2021
Martijn Pieters (@mjpieters) We have plans replacing this test adapter entirely, there are several issues with the current test adapter. This will be a temporary solution for this issue.
5 remaining items
The-Compiler commentedon Nov 4, 2021
As a workaround, you can use
pytest.paramto override the node ID for the problematic test (reference):also, FWIW:
Not a misspelling - English just happens to have four valid spellings of that word. pytest-parawtf to the rescue! (no, please don't use it in production...)
tests: Set IDs for urlmatch tests
Use pytest data to extract the parametrised decoration (#17881)
tests: Set IDs for urlmatch tests
tests: Set IDs for urlmatch tests
eleanorjboyd commentedon Sep 19, 2023
Hello! We have just finished our testing rewrite and are beginning the roll out to users. If you are able, it would be very helpful to know if your issue still exists on the rewrite! To try it yourself, add this setting to your users
settings.json"python.experiments.optInto": ["pythonTestAdapter"].You can confirm you have the rewrite enabled by setting
"python.analysis.logLevel": "Trace",in your user settings then check forExperiment 'pythonTestAdapter'is active in your python logs.Let me know if the rewrite fixes your issue. Thanks!
github-actions commentedon Oct 20, 2023
Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.
Happy Coding!