Skip to content

Commit 35ec30f

Browse files
authored
Fix for :::: in node id for pytest. (#19356)
1 parent 36e24e0 commit 35ec30f

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

pythonFiles/testing_tools/adapter/pytest/_pytest_item.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@
9595

9696
import sys
9797

98-
import pytest
9998
import _pytest.doctest
10099
import _pytest.unittest
100+
import pytest
101101

102102
from ..info import SingleTestInfo, SingleTestPath
103-
from ..util import fix_fileid, PATH_SEP, NORMCASE
103+
from ..util import NORMCASE, PATH_SEP, fix_fileid
104104

105105

106106
def should_never_reach_here(item, **extra):
@@ -508,6 +508,8 @@ def _normalize_test_id(
508508
"""Return the canonical form for the given node ID."""
509509
while "::()::" in testid:
510510
testid = testid.replace("::()::", "::")
511+
while ":::" in testid:
512+
testid = testid.replace(":::", "::")
511513
if kind is None:
512514
return testid, testid
513515
orig = testid

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,64 @@ def test_mysterious_parens(self):
14681468
],
14691469
)
14701470

1471+
def test_mysterious_colons(self):
1472+
stub = util.Stub()
1473+
discovered = StubDiscoveredTests(stub)
1474+
session = StubPytestSession(stub)
1475+
testroot = adapter_util.ABS_PATH(adapter_util.fix_path("/a/b/c"))
1476+
relfile = adapter_util.fix_path("x/y/z/test_eggs.py")
1477+
session.items = [
1478+
create_stub_function_item(
1479+
stub,
1480+
nodeid=relfile + "::SpamTests:::()::test_spam",
1481+
name="test_spam",
1482+
originalname=None,
1483+
location=(relfile, 12, "SpamTests.test_spam"),
1484+
path=adapter_util.PATH_JOIN(testroot, relfile),
1485+
function=FakeFunc("test_spam"),
1486+
),
1487+
]
1488+
collector = _discovery.TestCollector(tests=discovered)
1489+
1490+
collector.pytest_collection_finish(session)
1491+
1492+
self.maxDiff = None
1493+
self.assertEqual(
1494+
stub.calls,
1495+
[
1496+
("discovered.reset", None, None),
1497+
(
1498+
"discovered.add_test",
1499+
None,
1500+
dict(
1501+
parents=[
1502+
("./x/y/z/test_eggs.py::SpamTests", "SpamTests", "suite"),
1503+
("./x/y/z/test_eggs.py", "test_eggs.py", "file"),
1504+
("./x/y/z", "z", "folder"),
1505+
("./x/y", "y", "folder"),
1506+
("./x", "x", "folder"),
1507+
(".", testroot, "folder"),
1508+
],
1509+
test=info.SingleTestInfo(
1510+
id="./x/y/z/test_eggs.py::SpamTests::test_spam",
1511+
name="test_spam",
1512+
path=info.SingleTestPath(
1513+
root=testroot,
1514+
relfile=adapter_util.fix_relpath(relfile),
1515+
func="SpamTests.test_spam",
1516+
sub=[],
1517+
),
1518+
source="{}:{}".format(
1519+
adapter_util.fix_relpath(relfile), 13
1520+
),
1521+
markers=None,
1522+
parentid="./x/y/z/test_eggs.py::SpamTests",
1523+
),
1524+
),
1525+
),
1526+
],
1527+
)
1528+
14711529
def test_imported_test(self):
14721530
# pytest will even discover tests that were imported from
14731531
# another module!

0 commit comments

Comments
 (0)