@@ -1054,8 +1054,8 @@ def getlocation(function, curdir):
1054
1054
1055
1055
# builtin pytest.raises helper
1056
1056
1057
- def raises (ExpectedException , * args , ** kwargs ):
1058
- """ assert that a code block/function call raises @ExpectedException
1057
+ def raises (expected_exception , * args , ** kwargs ):
1058
+ """ assert that a code block/function call raises @expected_exception
1059
1059
and raise a failure exception otherwise.
1060
1060
1061
1061
This helper produces a ``py.code.ExceptionInfo()`` object.
@@ -1103,23 +1103,23 @@ def raises(ExpectedException, *args, **kwargs):
1103
1103
1104
1104
"""
1105
1105
__tracebackhide__ = True
1106
- if ExpectedException is AssertionError :
1106
+ if expected_exception is AssertionError :
1107
1107
# we want to catch a AssertionError
1108
1108
# replace our subclass with the builtin one
1109
1109
# see https://github.com/pytest-dev/pytest/issues/176
1110
1110
from _pytest .assertion .util import BuiltinAssertionError \
1111
- as ExpectedException
1111
+ as expected_exception
1112
1112
msg = ("exceptions must be old-style classes or"
1113
1113
" derived from BaseException, not %s" )
1114
- if isinstance (ExpectedException , tuple ):
1115
- for exc in ExpectedException :
1114
+ if isinstance (expected_exception , tuple ):
1115
+ for exc in expected_exception :
1116
1116
if not inspect .isclass (exc ):
1117
1117
raise TypeError (msg % type (exc ))
1118
- elif not inspect .isclass (ExpectedException ):
1119
- raise TypeError (msg % type (ExpectedException ))
1118
+ elif not inspect .isclass (expected_exception ):
1119
+ raise TypeError (msg % type (expected_exception ))
1120
1120
1121
1121
if not args :
1122
- return RaisesContext (ExpectedException )
1122
+ return RaisesContext (expected_exception )
1123
1123
elif isinstance (args [0 ], str ):
1124
1124
code , = args
1125
1125
assert isinstance (code , str )
@@ -1132,19 +1132,19 @@ def raises(ExpectedException, *args, **kwargs):
1132
1132
py .builtin .exec_ (code , frame .f_globals , loc )
1133
1133
# XXX didn'T mean f_globals == f_locals something special?
1134
1134
# this is destroyed here ...
1135
- except ExpectedException :
1135
+ except expected_exception :
1136
1136
return py .code .ExceptionInfo ()
1137
1137
else :
1138
1138
func = args [0 ]
1139
1139
try :
1140
1140
func (* args [1 :], ** kwargs )
1141
- except ExpectedException :
1141
+ except expected_exception :
1142
1142
return py .code .ExceptionInfo ()
1143
1143
pytest .fail ("DID NOT RAISE" )
1144
1144
1145
1145
class RaisesContext (object ):
1146
- def __init__ (self , ExpectedException ):
1147
- self .ExpectedException = ExpectedException
1146
+ def __init__ (self , expected_exception ):
1147
+ self .expected_exception = expected_exception
1148
1148
self .excinfo = None
1149
1149
1150
1150
def __enter__ (self ):
@@ -1163,14 +1163,14 @@ def __exit__(self, *tp):
1163
1163
exc_type , value , traceback = tp
1164
1164
tp = exc_type , exc_type (value ), traceback
1165
1165
self .excinfo .__init__ (tp )
1166
- return issubclass (self .excinfo .type , self .ExpectedException )
1166
+ return issubclass (self .excinfo .type , self .expected_exception )
1167
1167
1168
1168
# builtin pytest.warns helper
1169
1169
1170
- def warns (ExpectedWarning , * args , ** kwargs ):
1170
+ def warns (expected_warning , * args , ** kwargs ):
1171
1171
"""Assert that code raises a particular class of warning.
1172
1172
1173
- Specifically, the input ``ExpectedWarning`` can be a warning class or
1173
+ Specifically, the input @expected_warning can be a warning class or
1174
1174
tuple of warning classes, and the code must return that warning
1175
1175
(if a single class) or one of those warnings (if a tuple).
1176
1176
@@ -1186,14 +1186,14 @@ def warns(ExpectedWarning, *args, **kwargs):
1186
1186
1187
1187
msg = ("exceptions must be old-style classes or"
1188
1188
" derived from Warning, not %s" )
1189
- if isinstance (ExpectedWarning , tuple ):
1190
- for exc in ExpectedWarning :
1189
+ if isinstance (expected_warning , tuple ):
1190
+ for exc in expected_warning :
1191
1191
if not inspect .isclass (exc ):
1192
1192
raise TypeError (msg % type (exc ))
1193
- elif not inspect .isclass (ExpectedWarning ):
1194
- raise TypeError (msg % type (ExpectedWarning ))
1193
+ elif not inspect .isclass (expected_warning ):
1194
+ raise TypeError (msg % type (expected_warning ))
1195
1195
1196
- context = WarnsContext (ExpectedWarning )
1196
+ context = WarnsContext (expected_warning )
1197
1197
if not args :
1198
1198
return context
1199
1199
elif isinstance (args [0 ], str ):
@@ -1214,10 +1214,10 @@ def warns(ExpectedWarning, *args, **kwargs):
1214
1214
context .__exit__ (* sys .exc_info ())
1215
1215
1216
1216
class WarnsContext (object ):
1217
- def __init__ (self , ExpectedWarning ):
1218
- self .ExpectedWarning = (
1219
- ExpectedWarning if isinstance (ExpectedWarning , tuple ) else
1220
- (ExpectedWarning ,))
1217
+ def __init__ (self , expected_warning ):
1218
+ self .expected_warning = (
1219
+ expected_warning if isinstance (expected_warning , tuple ) else
1220
+ (expected_warning ,))
1221
1221
self .catcher = None
1222
1222
self .record = None
1223
1223
@@ -1228,7 +1228,7 @@ def __enter__(self):
1228
1228
1229
1229
def __exit__ (self , type , value , traceback ):
1230
1230
self .catcher .__exit__ (type , value , traceback )
1231
- if not any (r .category in self .ExpectedWarning for r in self .record ):
1231
+ if not any (r .category in self .expected_warning for r in self .record ):
1232
1232
pytest .fail ("DID NOT WARN" )
1233
1233
1234
1234
#
0 commit comments