File tree Expand file tree Collapse file tree 4 files changed +14
-0
lines changed Expand file tree Collapse file tree 4 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ Aron Coyle
44
44
Aron Curzon
45
45
Aviral Verma
46
46
Aviv Palivoda
47
+ Babak Keyvani
47
48
Barney Gale
48
49
Ben Gartner
49
50
Ben Webb
Original file line number Diff line number Diff line change
1
+ Improve :py:func: `pytest.raises `. Previously passing an empty tuple would give a confusing
2
+ error. We now raise immediately with a more helpful message.
Original file line number Diff line number Diff line change @@ -899,6 +899,13 @@ def raises(
899
899
"""
900
900
__tracebackhide__ = True
901
901
902
+ if expected_exception == ():
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'."
908
+ )
902
909
if isinstance (expected_exception , type ):
903
910
excepted_exceptions : Tuple [Type [E ], ...] = (expected_exception ,)
904
911
else :
Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ 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_empty_tuple (self ):
23
+ with pytest .raises (ValueError ):
24
+ pytest .raises (expected_exception = ())
25
+
22
26
def test_raises_callable_no_exception (self ) -> None :
23
27
class A :
24
28
def __call__ (self ):
You can’t perform that action at this time.
0 commit comments