summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-08-21 10:59:55 +0300
committerRan Benita <ran@unusedvar.com>2020-08-22 11:52:54 +0300
commit5e39cd5e71cb624dd5c3bf823a3c9168be3f0ff3 (patch)
tree395bf3584d770f2b014ea1f17db65715d1772f99 /src
parentd69abff2c7de8bc65b7f1ef867dec5b5b9c564bd (diff)
downloadpytest-5e39cd5e71cb624dd5c3bf823a3c9168be3f0ff3.tar.gz
main: improve message on `pytest path/to/a/directory::mytest`
The path part of a `<path>::part1::part2` style collection argument must be a file, not a directory. Previously this crashed with an uncool assert "invalid arg".
Diffstat (limited to 'src')
-rw-r--r--src/_pytest/main.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/_pytest/main.py b/src/_pytest/main.py
index 2abfffba0..7ff362c34 100644
--- a/src/_pytest/main.py
+++ b/src/_pytest/main.py
@@ -808,6 +808,7 @@ def resolve_collection_argument(
found module.
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("::")
if as_pypath:
@@ -821,4 +822,11 @@ def resolve_collection_argument(
else "file or directory not found: {arg}"
)
raise UsageError(msg.format(arg=arg))
+ if parts and fspath.is_dir():
+ msg = (
+ "package argument cannot contain :: selection parts: {arg}"
+ if as_pypath
+ else "directory argument cannot contain :: selection parts: {arg}"
+ )
+ raise UsageError(msg.format(arg=arg))
return py.path.local(str(fspath)), parts