Skip to content

Commit c326c04

Browse files
authored
Merge pull request #9642 from pytest-dev/run-testid-with-colon-colon
allow running testids which contain :: in the parametrized portion
2 parents efa16c2 + 2442034 commit c326c04

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

changelog/9642.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix running tests by id with ``::`` in the parametrize portion.

src/_pytest/main.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,10 @@ def resolve_collection_argument(
870870
If the path doesn't exist, raise UsageError.
871871
If the path is a directory and selection parts are present, raise UsageError.
872872
"""
873-
strpath, *parts = str(arg).split("::")
873+
base, squacket, rest = str(arg).partition("[")
874+
strpath, *parts = base.split("::")
875+
if parts:
876+
parts[-1] = f"{parts[-1]}{squacket}{rest}"
874877
if as_pypath:
875878
strpath = search_pypath(strpath)
876879
fspath = invocation_path / strpath

testing/test_main.py

+6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ def test_pypath(self, invocation_path: Path) -> None:
171171
invocation_path, "pkg::foo::bar", as_pypath=True
172172
)
173173

174+
def test_parametrized_name_with_colons(self, invocation_path: Path) -> None:
175+
ret = resolve_collection_argument(
176+
invocation_path, "src/pkg/test.py::test[a::b]"
177+
)
178+
assert ret == (invocation_path / "src/pkg/test.py", ["test[a::b]"])
179+
174180
def test_does_not_exist(self, invocation_path: Path) -> None:
175181
"""Given a file/module that does not exist raises UsageError."""
176182
with pytest.raises(

0 commit comments

Comments
 (0)