Skip to content

Commit

Permalink
pytest-dev#2953 fix comments: fix exception type
Browse files Browse the repository at this point in the history
  • Loading branch information
feuillemorte authored and alanbato committed Jan 24, 2018
1 parent f454802 commit c84edca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions _pytest/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
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

Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ def test_func(arg):


@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("""
Expand All @@ -355,7 +355,7 @@ def test_func(arg):
""")
opt, expected_result = spec
testdir.inline_run("-k", opt)
out = capsys.readouterr()[0]
out = capsys.readouterr().err
assert expected_result in out


Expand Down

0 comments on commit c84edca

Please sign in to comment.