From d1b50526fa8cb6aa602529619f4c07feb2d25676 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 20 Feb 2020 13:29:59 +0100 Subject: [PATCH] tests: harden some UsageError tests (matching the error msg) (#6775) --- testing/test_config.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/testing/test_config.py b/testing/test_config.py index d88241368d2..9f6042e4b9b 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -1,4 +1,5 @@ import os +import re import sys import textwrap @@ -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) @@ -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) == []