resolve_collection_argument no longer return an empty string when selection separator is specified to test name
This commit is contained in:
Abdelrahman Elbehery 2022-09-05 21:39:18 +02:00
parent 6ad32a9c5c
commit 7d192afeaf
2 changed files with 15 additions and 7 deletions

View File

@ -877,14 +877,16 @@ 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.
"""
base, squacket, rest = str(arg).partition("[")
strpath, *parts = base.split("::")
if parts:
strpath, selection, rest = arg.partition("::")
test_name, squacket, rest = rest.partition("[")
parts = []
if test_name:
parts = test_name.split("::")
parts[-1] = f"{parts[-1]}{squacket}{rest}"
if as_pypath:
strpath = search_pypath(strpath)
fspath = invocation_path / strpath
fspath = absolutepath(fspath)
fspath = absolutepath(invocation_path / strpath)
if not fspath.exists():
msg = (
"module or package not found: {arg} (missing __init__.py?)"
@ -892,7 +894,7 @@ def resolve_collection_argument(
else "file or directory not found: {arg}"
)
raise UsageError(msg.format(arg=arg))
if parts and fspath.is_dir():
if selection and fspath.is_dir():
msg = (
"package argument cannot contain :: selection parts: {arg}"
if as_pypath

View File

@ -142,7 +142,7 @@ class TestResolveCollectionArgument:
)
assert resolve_collection_argument(invocation_path, "src/pkg/test.py::") == (
invocation_path / "src/pkg/test.py",
[""],
[],
)
assert resolve_collection_argument(
invocation_path, "src/pkg/test.py::foo::bar"
@ -201,6 +201,12 @@ class TestResolveCollectionArgument:
):
resolve_collection_argument(invocation_path, "foobar")
with pytest.raises(
UsageError,
match=re.escape("file or directory not found: src/pkg/test.py[a::b]"),
):
resolve_collection_argument(invocation_path, "src/pkg/test.py[a::b]")
with pytest.raises(
UsageError,
match=re.escape(