Skip to content

Commit 3e6a12c

Browse files
committed
Make 'raises' and 'warns' args PEP8 compliant
1 parent 11fde08 commit 3e6a12c

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

_pytest/python.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,8 @@ def getlocation(function, curdir):
10541054

10551055
# builtin pytest.raises helper
10561056

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
10591059
and raise a failure exception otherwise.
10601060
10611061
This helper produces a ``py.code.ExceptionInfo()`` object.
@@ -1103,23 +1103,23 @@ def raises(ExpectedException, *args, **kwargs):
11031103
11041104
"""
11051105
__tracebackhide__ = True
1106-
if ExpectedException is AssertionError:
1106+
if expected_exception is AssertionError:
11071107
# we want to catch a AssertionError
11081108
# replace our subclass with the builtin one
11091109
# see https://github.com/pytest-dev/pytest/issues/176
11101110
from _pytest.assertion.util import BuiltinAssertionError \
1111-
as ExpectedException
1111+
as expected_exception
11121112
msg = ("exceptions must be old-style classes or"
11131113
" 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:
11161116
if not inspect.isclass(exc):
11171117
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))
11201120

11211121
if not args:
1122-
return RaisesContext(ExpectedException)
1122+
return RaisesContext(expected_exception)
11231123
elif isinstance(args[0], str):
11241124
code, = args
11251125
assert isinstance(code, str)
@@ -1132,19 +1132,19 @@ def raises(ExpectedException, *args, **kwargs):
11321132
py.builtin.exec_(code, frame.f_globals, loc)
11331133
# XXX didn'T mean f_globals == f_locals something special?
11341134
# this is destroyed here ...
1135-
except ExpectedException:
1135+
except expected_exception:
11361136
return py.code.ExceptionInfo()
11371137
else:
11381138
func = args[0]
11391139
try:
11401140
func(*args[1:], **kwargs)
1141-
except ExpectedException:
1141+
except expected_exception:
11421142
return py.code.ExceptionInfo()
11431143
pytest.fail("DID NOT RAISE")
11441144

11451145
class RaisesContext(object):
1146-
def __init__(self, ExpectedException):
1147-
self.ExpectedException = ExpectedException
1146+
def __init__(self, expected_exception):
1147+
self.expected_exception = expected_exception
11481148
self.excinfo = None
11491149

11501150
def __enter__(self):
@@ -1163,14 +1163,14 @@ def __exit__(self, *tp):
11631163
exc_type, value, traceback = tp
11641164
tp = exc_type, exc_type(value), traceback
11651165
self.excinfo.__init__(tp)
1166-
return issubclass(self.excinfo.type, self.ExpectedException)
1166+
return issubclass(self.excinfo.type, self.expected_exception)
11671167

11681168
# builtin pytest.warns helper
11691169

1170-
def warns(ExpectedWarning, *args, **kwargs):
1170+
def warns(expected_warning, *args, **kwargs):
11711171
"""Assert that code raises a particular class of warning.
11721172
1173-
Specifically, the input ``ExpectedWarning`` can be a warning class or
1173+
Specifically, the input @expected_warning can be a warning class or
11741174
tuple of warning classes, and the code must return that warning
11751175
(if a single class) or one of those warnings (if a tuple).
11761176
@@ -1186,14 +1186,14 @@ def warns(ExpectedWarning, *args, **kwargs):
11861186

11871187
msg = ("exceptions must be old-style classes or"
11881188
" 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:
11911191
if not inspect.isclass(exc):
11921192
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))
11951195

1196-
context = WarnsContext(ExpectedWarning)
1196+
context = WarnsContext(expected_warning)
11971197
if not args:
11981198
return context
11991199
elif isinstance(args[0], str):
@@ -1214,10 +1214,10 @@ def warns(ExpectedWarning, *args, **kwargs):
12141214
context.__exit__(*sys.exc_info())
12151215

12161216
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,))
12211221
self.catcher = None
12221222
self.record = None
12231223

@@ -1228,7 +1228,7 @@ def __enter__(self):
12281228

12291229
def __exit__(self, type, value, traceback):
12301230
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):
12321232
pytest.fail("DID NOT WARN")
12331233

12341234
#

0 commit comments

Comments
 (0)