#2953 fix comments: fix exception type
This commit is contained in:
		
							parent
							
								
									5d3f7d7142
								
							
						
					
					
						commit
						8433e2ba04
					
				|  | @ -8,6 +8,8 @@ import attr | ||||||
| from collections import namedtuple | from collections import namedtuple | ||||||
| from operator import attrgetter | from operator import attrgetter | ||||||
| from six.moves import map | from six.moves import map | ||||||
|  | 
 | ||||||
|  | from _pytest.config import UsageError | ||||||
| from .deprecated import MARK_PARAMETERSET_UNPACKING | from .deprecated import MARK_PARAMETERSET_UNPACKING | ||||||
| from .compat import NOTSET, getfslineno | from .compat import NOTSET, getfslineno | ||||||
| 
 | 
 | ||||||
|  | @ -265,11 +267,11 @@ def matchkeyword(colitem, keywordexpr): | ||||||
|         return not mapping[keywordexpr[4:]] |         return not mapping[keywordexpr[4:]] | ||||||
|     for kwd in keywordexpr.split(): |     for kwd in keywordexpr.split(): | ||||||
|         if keyword.iskeyword(kwd) and kwd not in python_keywords_allowed_list: |         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: |     try: | ||||||
|         return eval(keywordexpr, {}, mapping) |         return eval(keywordexpr, {}, mapping) | ||||||
|     except SyntaxError: |     except SyntaxError: | ||||||
|         raise AttributeError("Wrong expression passed to '-k': {}".format(keywordexpr)) |         raise UsageError("Wrong expression passed to '-k': {}".format(keywordexpr)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def pytest_configure(config): | def pytest_configure(config): | ||||||
|  |  | ||||||
|  | @ -345,8 +345,8 @@ def test_keyword_option_parametrize(spec, testdir): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.parametrize("spec", [ | @pytest.mark.parametrize("spec", [ | ||||||
|     ("foo or import", "AttributeError: Python keyword 'import' not accepted in expressions passed to '-k'"), |     ("foo or import", "ERROR: Python keyword 'import' not accepted in expressions passed to '-k'"), | ||||||
|     ("foo or", "AttributeError: Wrong expression passed to '-k': foo or") |     ("foo or", "ERROR: Wrong expression passed to '-k': foo or") | ||||||
| ]) | ]) | ||||||
| def test_keyword_option_wrong_arguments(spec, testdir, capsys): | def test_keyword_option_wrong_arguments(spec, testdir, capsys): | ||||||
|     testdir.makepyfile(""" |     testdir.makepyfile(""" | ||||||
|  | @ -355,7 +355,7 @@ def test_keyword_option_wrong_arguments(spec, testdir, capsys): | ||||||
|         """) |         """) | ||||||
|     opt, expected_result = spec |     opt, expected_result = spec | ||||||
|     testdir.inline_run("-k", opt) |     testdir.inline_run("-k", opt) | ||||||
|     out = capsys.readouterr()[0] |     out = capsys.readouterr().err | ||||||
|     assert expected_result in out |     assert expected_result in out | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue