fix for #10273
resolve_collection_argument no longer return an empty string when selection separator is specified to test name
This commit is contained in:
parent
6ad32a9c5c
commit
7d192afeaf
|
@ -877,14 +877,16 @@ def resolve_collection_argument(
|
||||||
If the path doesn't exist, raise UsageError.
|
If the path doesn't exist, raise UsageError.
|
||||||
If the path is a directory and selection parts are present, raise UsageError.
|
If the path is a directory and selection parts are present, raise UsageError.
|
||||||
"""
|
"""
|
||||||
base, squacket, rest = str(arg).partition("[")
|
strpath, selection, rest = arg.partition("::")
|
||||||
strpath, *parts = base.split("::")
|
test_name, squacket, rest = rest.partition("[")
|
||||||
if parts:
|
parts = []
|
||||||
|
|
||||||
|
if test_name:
|
||||||
|
parts = test_name.split("::")
|
||||||
parts[-1] = f"{parts[-1]}{squacket}{rest}"
|
parts[-1] = f"{parts[-1]}{squacket}{rest}"
|
||||||
if as_pypath:
|
if as_pypath:
|
||||||
strpath = search_pypath(strpath)
|
strpath = search_pypath(strpath)
|
||||||
fspath = invocation_path / strpath
|
fspath = absolutepath(invocation_path / strpath)
|
||||||
fspath = absolutepath(fspath)
|
|
||||||
if not fspath.exists():
|
if not fspath.exists():
|
||||||
msg = (
|
msg = (
|
||||||
"module or package not found: {arg} (missing __init__.py?)"
|
"module or package not found: {arg} (missing __init__.py?)"
|
||||||
|
@ -892,7 +894,7 @@ def resolve_collection_argument(
|
||||||
else "file or directory not found: {arg}"
|
else "file or directory not found: {arg}"
|
||||||
)
|
)
|
||||||
raise UsageError(msg.format(arg=arg))
|
raise UsageError(msg.format(arg=arg))
|
||||||
if parts and fspath.is_dir():
|
if selection and fspath.is_dir():
|
||||||
msg = (
|
msg = (
|
||||||
"package argument cannot contain :: selection parts: {arg}"
|
"package argument cannot contain :: selection parts: {arg}"
|
||||||
if as_pypath
|
if as_pypath
|
||||||
|
|
|
@ -142,7 +142,7 @@ class TestResolveCollectionArgument:
|
||||||
)
|
)
|
||||||
assert resolve_collection_argument(invocation_path, "src/pkg/test.py::") == (
|
assert resolve_collection_argument(invocation_path, "src/pkg/test.py::") == (
|
||||||
invocation_path / "src/pkg/test.py",
|
invocation_path / "src/pkg/test.py",
|
||||||
[""],
|
[],
|
||||||
)
|
)
|
||||||
assert resolve_collection_argument(
|
assert resolve_collection_argument(
|
||||||
invocation_path, "src/pkg/test.py::foo::bar"
|
invocation_path, "src/pkg/test.py::foo::bar"
|
||||||
|
@ -201,6 +201,12 @@ class TestResolveCollectionArgument:
|
||||||
):
|
):
|
||||||
resolve_collection_argument(invocation_path, "foobar")
|
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(
|
with pytest.raises(
|
||||||
UsageError,
|
UsageError,
|
||||||
match=re.escape(
|
match=re.escape(
|
||||||
|
|
Loading…
Reference in New Issue