diff options
author | Ran Benita <ran@unusedvar.com> | 2020-08-21 10:59:55 +0300 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2020-08-22 11:52:54 +0300 |
commit | 5e39cd5e71cb624dd5c3bf823a3c9168be3f0ff3 (patch) | |
tree | 395bf3584d770f2b014ea1f17db65715d1772f99 /testing | |
parent | d69abff2c7de8bc65b7f1ef867dec5b5b9c564bd (diff) | |
download | pytest-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 'testing')
-rw-r--r-- | testing/test_main.py | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/testing/test_main.py b/testing/test_main.py index 4546c83ba..71eae16b0 100644 --- a/testing/test_main.py +++ b/testing/test_main.py @@ -136,23 +136,21 @@ class TestResolveCollectionArgument: ["foo", "bar", ""], ) - def test_dir(self, root): + def test_dir(self, root: py.path.local) -> None: """Directory and parts.""" assert resolve_collection_argument(root, "src/pkg") == (root / "src/pkg", []) - assert resolve_collection_argument(root, "src/pkg::") == ( - root / "src/pkg", - [""], - ) - assert resolve_collection_argument(root, "src/pkg::foo::bar") == ( - root / "src/pkg", - ["foo", "bar"], - ) - assert resolve_collection_argument(root, "src/pkg::foo::bar::") == ( - root / "src/pkg", - ["foo", "bar", ""], - ) - def test_pypath(self, root): + with pytest.raises( + UsageError, match=r"directory argument cannot contain :: selection parts" + ): + resolve_collection_argument(root, "src/pkg::") + + with pytest.raises( + UsageError, match=r"directory argument cannot contain :: selection parts" + ): + resolve_collection_argument(root, "src/pkg::foo::bar") + + def test_pypath(self, root: py.path.local) -> None: """Dotted name and parts.""" assert resolve_collection_argument(root, "pkg.test", as_pypath=True) == ( root / "src/pkg/test.py", @@ -165,10 +163,11 @@ class TestResolveCollectionArgument: root / "src/pkg", [], ) - assert resolve_collection_argument(root, "pkg::foo::bar", as_pypath=True) == ( - root / "src/pkg", - ["foo", "bar"], - ) + + with pytest.raises( + UsageError, match=r"package argument cannot contain :: selection parts" + ): + resolve_collection_argument(root, "pkg::foo::bar", as_pypath=True) def test_does_not_exist(self, root): """Given a file/module that does not exist raises UsageError.""" |