Skip to content

Commit

Permalink
tests: harden some UsageError tests (matching the error msg) (pytest-…
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Feb 20, 2020
1 parent 4d633a2 commit d1b5052
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions testing/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import sys
import textwrap

Expand Down Expand Up @@ -408,11 +409,12 @@ def pytest_addoption(parser):

def test_confcutdir_check_isdir(self, testdir):
"""Give an error if --confcutdir is not a valid directory (#2078)"""
with pytest.raises(pytest.UsageError):
exp_match = r"^--confcutdir must be a directory, given: "
with pytest.raises(pytest.UsageError, match=exp_match):
testdir.parseconfig(
"--confcutdir", testdir.tmpdir.join("file").ensure(file=1)
)
with pytest.raises(pytest.UsageError):
with pytest.raises(pytest.UsageError, match=exp_match):
testdir.parseconfig("--confcutdir", testdir.tmpdir.join("inexistant"))
config = testdir.parseconfig(
"--confcutdir", testdir.tmpdir.join("dir").ensure(dir=1)
Expand Down Expand Up @@ -846,9 +848,17 @@ def pytest_load_initial_conftests(self):
def test_get_plugin_specs_as_list():
from _pytest.config import _get_plugin_specs_as_list

with pytest.raises(pytest.UsageError):
def exp_match(val):
return (
"Plugin specs must be a ','-separated string"
" or a list/tuple of strings for plugin names. Given: {}".format(
re.escape(repr(val))
)
)

with pytest.raises(pytest.UsageError, match=exp_match({"foo"})):
_get_plugin_specs_as_list({"foo"})
with pytest.raises(pytest.UsageError):
with pytest.raises(pytest.UsageError, match=exp_match({})):
_get_plugin_specs_as_list(dict())

assert _get_plugin_specs_as_list(None) == []
Expand Down

0 comments on commit d1b5052

Please sign in to comment.