File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -899,12 +899,11 @@ def raises(
899
899
"""
900
900
__tracebackhide__ = True
901
901
902
- if expected_exception == () :
902
+ if not expected_exception :
903
903
raise ValueError (
904
- "Passing expected_exception=() is an error, because it's impossible to "
905
- "raise an exception which is not an instance of any type. Raising exceptions "
906
- "is already understood as failing the test, so you don't need any special "
907
- "code to say 'this should never raise an exception'."
904
+ f"Expected an exception type or a tuple of exception types, but got `{ expected_exception !r} `. "
905
+ f"Raising exceptions is already understood as failing the test, so you don't need "
906
+ f"any special code to say 'this should never raise an exception'."
908
907
)
909
908
if isinstance (expected_exception , type ):
910
909
excepted_exceptions : Tuple [Type [E ], ...] = (expected_exception ,)
Original file line number Diff line number Diff line change @@ -19,8 +19,12 @@ def test_raises_function(self):
19
19
excinfo = pytest .raises (ValueError , int , "hello" )
20
20
assert "invalid literal" in str (excinfo .value )
21
21
22
+ def test_raises_does_not_allow_none (self ):
23
+ with pytest .raises (ValueError , match = "Expected an exception type or" ):
24
+ pytest .raises (expected_exception = None )
25
+
22
26
def test_raises_does_not_allow_empty_tuple (self ):
23
- with pytest .raises (ValueError ):
27
+ with pytest .raises (ValueError , match = "Expected an exception type or" ):
24
28
pytest .raises (expected_exception = ())
25
29
26
30
def test_raises_callable_no_exception (self ) -> None :
You can’t perform that action at this time.
0 commit comments