Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
resolve_collection_argument no longer return an empty string when selection separator is specified to test name
  • Loading branch information
elbehery95 committed Sep 5, 2022
1 parent 6ad32a9 commit 7d192af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,22 +877,24 @@ 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?)"
if as_pypath
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
Expand Down
8 changes: 7 additions & 1 deletion testing/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_file(self, invocation_path: Path) -> None:
)
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"
Expand Down Expand Up @@ -201,6 +201,12 @@ def test_does_not_exist(self, invocation_path: Path) -> None:
):
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(
Expand Down

0 comments on commit 7d192af

Please sign in to comment.