Skip to content

Commit

Permalink
Fix for :::: in node id for pytest.
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Jun 24, 2022
1 parent 62273c1 commit ca0c083
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pythonFiles/testing_tools/adapter/pytest/_pytest_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@

import sys

import pytest
import _pytest.doctest
import _pytest.unittest
import pytest

from ..info import SingleTestInfo, SingleTestPath
from ..util import fix_fileid, PATH_SEP, NORMCASE
from ..util import NORMCASE, PATH_SEP, fix_fileid


def should_never_reach_here(item, **extra):
Expand Down Expand Up @@ -508,6 +508,8 @@ def _normalize_test_id(
"""Return the canonical form for the given node ID."""
while "::()::" in testid:
testid = testid.replace("::()::", "::")
while ":::" in testid:
testid = testid.replace(":::", "::")
if kind is None:
return testid, testid
orig = testid
Expand Down
58 changes: 58 additions & 0 deletions pythonFiles/tests/testing_tools/adapter/pytest/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,64 @@ def test_mysterious_parens(self):
],
)

def test_mysterious_colons(self):
stub = util.Stub()
discovered = StubDiscoveredTests(stub)
session = StubPytestSession(stub)
testroot = adapter_util.ABS_PATH(adapter_util.fix_path("/a/b/c"))
relfile = adapter_util.fix_path("x/y/z/test_eggs.py")
session.items = [
create_stub_function_item(
stub,
nodeid=relfile + "::SpamTests:::()::test_spam",
name="test_spam",
originalname=None,
location=(relfile, 12, "SpamTests.test_spam"),
path=adapter_util.PATH_JOIN(testroot, relfile),
function=FakeFunc("test_spam"),
),
]
collector = _discovery.TestCollector(tests=discovered)

collector.pytest_collection_finish(session)

self.maxDiff = None
self.assertEqual(
stub.calls,
[
("discovered.reset", None, None),
(
"discovered.add_test",
None,
dict(
parents=[
("./x/y/z/test_eggs.py::SpamTests", "SpamTests", "suite"),
("./x/y/z/test_eggs.py", "test_eggs.py", "file"),
("./x/y/z", "z", "folder"),
("./x/y", "y", "folder"),
("./x", "x", "folder"),
(".", testroot, "folder"),
],
test=info.SingleTestInfo(
id="./x/y/z/test_eggs.py::SpamTests::test_spam",
name="test_spam",
path=info.SingleTestPath(
root=testroot,
relfile=adapter_util.fix_relpath(relfile),
func="SpamTests.test_spam",
sub=[],
),
source="{}:{}".format(
adapter_util.fix_relpath(relfile), 13
),
markers=None,
parentid="./x/y/z/test_eggs.py::SpamTests",
),
),
),
],
)

def test_imported_test(self):
# pytest will even discover tests that were imported from
# another module!
Expand Down

0 comments on commit ca0c083

Please sign in to comment.