GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use pytest data to extract the parametrised decoration (#17881) · haedeu/vscode-python@251cb30

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • news/2 Fixes
    • 17676.md
  • pythonFiles
    • testing_tools/adapter/pytest
      • _pytest_item.py
    • tests/testing_tools/adapter/pytest
      • test_discovery.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎news/2 Fixes/17676.md‎

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
When parsing pytest node ids with parameters, use native pytest information to separate out the parameter decoration rather than try and parse the nodeid as text.
2+
(thanks [Martijn Pieters](https://github.com/mjpieters))
Collapse file

‎pythonFiles/testing_tools/adapter/pytest/_pytest_item.py‎

Copy file name to clipboardExpand all lines: pythonFiles/testing_tools/adapter/pytest/_pytest_item.py
+15-39Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,21 @@ def parse_item(
158158
# Skip plugin generated tests
159159
if kind is None:
160160
return None, None
161-
(nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
162-
item.nodeid, kind
163-
)
161+
162+
if kind == "function" and item.originalname and item.originalname != item.name:
163+
# split out parametrized decorations `node[params]`) before parsing
164+
# and manually attach parametrized portion back in when done.
165+
parameterized = item.name[len(item.originalname) :]
166+
(parentid, parents, fileid, testfunc, _) = _parse_node_id(
167+
item.nodeid[: -len(parameterized)], kind
168+
)
169+
nodeid = "{}{}".format(parentid, parameterized)
170+
parents = [(parentid, item.originalname, kind)] + parents
171+
else:
172+
(nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(
173+
item.nodeid, kind
174+
)
175+
164176
# Note: testfunc does not necessarily match item.function.__name__.
165177
# This can result from importing a test function from another module.
166178

@@ -434,32 +446,6 @@ def _parse_node_id(
434446
)
435447

436448

437-
def _find_left_bracket(nodeid):
438-
"""Return tuple of part before final bracket open, separator [, and the remainder.
439-
Notes:
440-
Testcase names in case of parametrized tests are wrapped in [<test-case-name>].
441-
Examples:
442-
dirname[sometext]/dirname/testfile.py::testset::testname[testcase]
443-
=> ('dirname[sometext]/dirname/testfile.py::testset::testname', '[', 'testcase]')
444-
dirname/dirname/testfile.py::testset::testname[testcase]
445-
=> ('dirname/dirname/testfile.py::testset::testname', '[', 'testcase]')
446-
dirname/dirname/testfile.py::testset::testname[testcase[x]]
447-
=> ('dirname/dirname/testfile.py::testset::testname', '[', 'testcase[x]]')
448-
"""
449-
if not nodeid.endswith("]"):
450-
return nodeid, "", ""
451-
bracketcount = 0
452-
for index, char in enumerate(nodeid[::-1]):
453-
if char == "]":
454-
bracketcount += 1
455-
elif char == "[":
456-
bracketcount -= 1
457-
if bracketcount == 0:
458-
n = len(nodeid) - 1 - index
459-
return nodeid[:n], nodeid[n], nodeid[n + 1 :]
460-
return nodeid, "", ""
461-
462-
463449
def _iter_nodes(
464450
testid,
465451
kind,
@@ -473,16 +459,6 @@ def _iter_nodes(
473459
if len(nodeid) > len(testid):
474460
testid = "." + _pathsep + testid
475461

476-
if kind == "function" and nodeid.endswith("]"):
477-
funcid, sep, parameterized = _find_left_bracket(nodeid)
478-
if not sep:
479-
raise should_never_reach_here(
480-
nodeid,
481-
# ...
482-
)
483-
yield (nodeid, sep + parameterized, "subtest")
484-
nodeid = funcid
485-
486462
parentid, _, name = nodeid.rpartition("::")
487463
if not parentid:
488464
if kind is None:
Collapse file

‎pythonFiles/tests/testing_tools/adapter/pytest/test_discovery.py‎

Copy file name to clipboardExpand all lines: pythonFiles/tests/testing_tools/adapter/pytest/test_discovery.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ def test_modifyitems(self):
530530
stub,
531531
nodeid="test_spam.py::SpamTests::test_one",
532532
name="test_one",
533+
originalname=None,
533534
location=("test_spam.py", 12, "SpamTests.test_one"),
534535
fspath=adapter_util.PATH_JOIN(testroot, "test_spam.py"),
535536
function=FakeFunc("test_one"),
@@ -538,6 +539,7 @@ def test_modifyitems(self):
538539
stub,
539540
nodeid="test_spam.py::SpamTests::test_other",
540541
name="test_other",
542+
originalname=None,
541543
location=("test_spam.py", 19, "SpamTests.test_other"),
542544
fspath=adapter_util.PATH_JOIN(testroot, "test_spam.py"),
543545
function=FakeFunc("test_other"),
@@ -546,6 +548,7 @@ def test_modifyitems(self):
546548
stub,
547549
nodeid="test_spam.py::test_all",
548550
name="test_all",
551+
originalname=None,
549552
location=("test_spam.py", 144, "test_all"),
550553
fspath=adapter_util.PATH_JOIN(testroot, "test_spam.py"),
551554
function=FakeFunc("test_all"),
@@ -554,6 +557,7 @@ def test_modifyitems(self):
554557
stub,
555558
nodeid="test_spam.py::test_each[10-10]",
556559
name="test_each[10-10]",
560+
originalname="test_each",
557561
location=("test_spam.py", 273, "test_each[10-10]"),
558562
fspath=adapter_util.PATH_JOIN(testroot, "test_spam.py"),
559563
function=FakeFunc("test_each"),
@@ -562,6 +566,7 @@ def test_modifyitems(self):
562566
stub,
563567
nodeid=relfile2 + "::All::BasicTests::test_first",
564568
name="test_first",
569+
originalname=None,
565570
location=(relfile2, 31, "All.BasicTests.test_first"),
566571
fspath=adapter_util.PATH_JOIN(testroot, relfile2),
567572
function=FakeFunc("test_first"),
@@ -570,6 +575,7 @@ def test_modifyitems(self):
570575
stub,
571576
nodeid=relfile2 + "::All::BasicTests::test_each[1+2-3]",
572577
name="test_each[1+2-3]",
578+
originalname="test_each",
573579
location=(relfile2, 62, "All.BasicTests.test_each[1+2-3]"),
574580
fspath=adapter_util.PATH_JOIN(testroot, relfile2),
575581
function=FakeFunc("test_each"),
@@ -781,6 +787,7 @@ def test_finish(self):
781787
stub,
782788
nodeid=relfile + "::SpamTests::test_spam",
783789
name="test_spam",
790+
originalname=None,
784791
location=(relfile, 12, "SpamTests.test_spam"),
785792
fspath=adapter_util.PATH_JOIN(testroot, relfile),
786793
function=FakeFunc("test_spam"),
@@ -992,6 +999,7 @@ def test_nested_brackets(self):
992999
stub,
9931000
nodeid=relfile + "::SpamTests::test_spam[a-[b]-c]",
9941001
name="test_spam[a-[b]-c]",
1002+
originalname="test_spam",
9951003
location=(relfile, 12, "SpamTests.test_spam[a-[b]-c]"),
9961004
fspath=adapter_util.PATH_JOIN(testroot, relfile),
9971005
function=FakeFunc("test_spam"),
@@ -1054,6 +1062,7 @@ def test_nested_suite(self):
10541062
stub,
10551063
nodeid=relfile + "::SpamTests::Ham::Eggs::test_spam",
10561064
name="test_spam",
1065+
originalname=None,
10571066
location=(relfile, 12, "SpamTests.Ham.Eggs.test_spam"),
10581067
fspath=adapter_util.PATH_JOIN(testroot, relfile),
10591068
function=FakeFunc("test_spam"),
@@ -1120,6 +1129,7 @@ def test_windows(self):
11201129
# pytest always uses "/" as the path separator in node IDs:
11211130
nodeid="X/Y/Z/test_Eggs.py::SpamTests::test_spam",
11221131
name="test_spam",
1132+
originalname=None,
11231133
# normal path separator (contrast with nodeid):
11241134
location=(relfile, 12, "SpamTests.test_spam"),
11251135
# path separator matches location:
@@ -1152,6 +1162,7 @@ def test_windows(self):
11521162
stub,
11531163
nodeid=fileid + "::test_spam",
11541164
name="test_spam",
1165+
originalname=None,
11551166
location=(locfile, 12, "test_spam"),
11561167
fspath=fspath,
11571168
function=FakeFunc("test_spam"),
@@ -1412,6 +1423,7 @@ def test_mysterious_parens(self):
14121423
stub,
14131424
nodeid=relfile + "::SpamTests::()::()::test_spam",
14141425
name="test_spam",
1426+
originalname=None,
14151427
location=(relfile, 12, "SpamTests.test_spam"),
14161428
fspath=adapter_util.PATH_JOIN(testroot, relfile),
14171429
function=FakeFunc("test_spam"),
@@ -1472,6 +1484,7 @@ def test_imported_test(self):
14721484
stub,
14731485
nodeid=relfile + "::SpamTests::test_spam",
14741486
name="test_spam",
1487+
originalname=None,
14751488
location=(srcfile, 12, "SpamTests.test_spam"),
14761489
fspath=adapter_util.PATH_JOIN(testroot, relfile),
14771490
function=FakeFunc("test_spam"),
@@ -1480,6 +1493,7 @@ def test_imported_test(self):
14801493
stub,
14811494
nodeid=relfile + "::test_ham",
14821495
name="test_ham",
1496+
originalname=None,
14831497
location=(srcfile, 3, "test_ham"),
14841498
fspath=adapter_util.PATH_JOIN(testroot, relfile),
14851499
function=FakeFunc("test_spam"),

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.