diff --git a/_pytest/mark.py b/_pytest/mark.py index 4f6fc5813..6d095a592 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -8,6 +8,8 @@ import attr from collections import namedtuple from operator import attrgetter from six.moves import map + +from _pytest.config import UsageError from .deprecated import MARK_PARAMETERSET_UNPACKING from .compat import NOTSET, getfslineno @@ -265,11 +267,11 @@ def matchkeyword(colitem, keywordexpr): return not mapping[keywordexpr[4:]] for kwd in keywordexpr.split(): if keyword.iskeyword(kwd) and kwd not in python_keywords_allowed_list: - raise AttributeError("Python keyword '{}' not accepted in expressions passed to '-k'".format(kwd)) + raise UsageError("Python keyword '{}' not accepted in expressions passed to '-k'".format(kwd)) try: return eval(keywordexpr, {}, mapping) except SyntaxError: - raise AttributeError("Wrong expression passed to '-k': {}".format(keywordexpr)) + raise UsageError("Wrong expression passed to '-k': {}".format(keywordexpr)) def pytest_configure(config): diff --git a/testing/test_mark.py b/testing/test_mark.py index f3a7af1d1..45e88ae8f 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -345,8 +345,8 @@ def test_keyword_option_parametrize(spec, testdir): @pytest.mark.parametrize("spec", [ - ("foo or import", "AttributeError: Python keyword 'import' not accepted in expressions passed to '-k'"), - ("foo or", "AttributeError: Wrong expression passed to '-k': foo or") + ("foo or import", "ERROR: Python keyword 'import' not accepted in expressions passed to '-k'"), + ("foo or", "ERROR: Wrong expression passed to '-k': foo or") ]) def test_keyword_option_wrong_arguments(spec, testdir, capsys): testdir.makepyfile(""" @@ -355,7 +355,7 @@ def test_keyword_option_wrong_arguments(spec, testdir, capsys): """) opt, expected_result = spec testdir.inline_run("-k", opt) - out = capsys.readouterr()[0] + out = capsys.readouterr().err assert expected_result in out