Consolidate behavior by using filterfalse and always_iterable

This commit is contained in:
Jason R. Coombs 2018-02-27 03:38:56 -05:00
parent 44fa5a77d4
commit cfaf3600c1
2 changed files with 7 additions and 9 deletions

View File

@ -2,7 +2,8 @@ import math
import sys import sys
import py import py
from six.moves import zip from six.moves import zip, filterfalse
from more_itertools.more import always_iterable
from _pytest.compat import isclass from _pytest.compat import isclass
from _pytest.outcomes import fail from _pytest.outcomes import fail
@ -566,14 +567,10 @@ def raises(expected_exception, *args, **kwargs):
""" """
__tracebackhide__ = True __tracebackhide__ = True
msg = ("exceptions must be old-style classes or" for exc in filterfalse(isclass, always_iterable(expected_exception)):
" derived from BaseException, not %s") msg = ("exceptions must be old-style classes or"
if isinstance(expected_exception, tuple): " derived from BaseException, not %s")
for exc in expected_exception: raise TypeError(msg % type(exc))
if not isclass(exc):
raise TypeError(msg % type(exc))
elif not isclass(expected_exception):
raise TypeError(msg % type(expected_exception))
message = "DID NOT RAISE {0}".format(expected_exception) message = "DID NOT RAISE {0}".format(expected_exception)
match_expr = None match_expr = None

View File

@ -60,6 +60,7 @@ def main():
'six>=1.10.0', 'six>=1.10.0',
'setuptools', 'setuptools',
'attrs>=17.2.0', 'attrs>=17.2.0',
'more_itertools>=4.0.0',
] ]
# if _PYTEST_SETUP_SKIP_PLUGGY_DEP is set, skip installing pluggy; # if _PYTEST_SETUP_SKIP_PLUGGY_DEP is set, skip installing pluggy;
# used by tox.ini to test with pluggy master # used by tox.ini to test with pluggy master