From 919384ca47d611bf9f94a986b09daf85ca5b7d09 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 7 Feb 2022 20:17:14 -0500 Subject: [PATCH] allow running testids which contain :: in the parametrized portion --- src/_pytest/main.py | 5 ++++- testing/test_main.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index afe613fd0d9..8f590754ae0 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -870,7 +870,10 @@ def resolve_collection_argument( If the path doesn't exist, raise UsageError. If the path is a directory and selection parts are present, raise UsageError. """ - strpath, *parts = str(arg).split("::") + base, squacket, rest = str(arg).partition("[") + strpath, *parts = base.split("::") + if parts: + parts[-1] = f"{parts[-1]}{squacket}{rest}" if as_pypath: strpath = search_pypath(strpath) fspath = invocation_path / strpath diff --git a/testing/test_main.py b/testing/test_main.py index 6a13633f6a9..926715a8c47 100644 --- a/testing/test_main.py +++ b/testing/test_main.py @@ -171,6 +171,12 @@ def test_pypath(self, invocation_path: Path) -> None: invocation_path, "pkg::foo::bar", as_pypath=True ) + def test_parametrized_name_with_colons(self, invocation_path: Path) -> None: + ret = resolve_collection_argument( + invocation_path, "src/pkg/test.py::test[a::b]" + ) + assert ret == (invocation_path / "src/pkg/test.py", ["test[a::b]"]) + def test_does_not_exist(self, invocation_path: Path) -> None: """Given a file/module that does not exist raises UsageError.""" with pytest.raises(