From cfaf3600c1d9ea2b45d9b801a47379304fd7e455 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 27 Feb 2018 03:38:56 -0500 Subject: [PATCH 1/2] Consolidate behavior by using filterfalse and always_iterable --- _pytest/python_api.py | 15 ++++++--------- setup.py | 1 + 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/_pytest/python_api.py b/_pytest/python_api.py index 541371449..3dce7f6b4 100644 --- a/_pytest/python_api.py +++ b/_pytest/python_api.py @@ -2,7 +2,8 @@ import math import sys 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.outcomes import fail @@ -566,14 +567,10 @@ def raises(expected_exception, *args, **kwargs): """ __tracebackhide__ = True - msg = ("exceptions must be old-style classes or" - " derived from BaseException, not %s") - if isinstance(expected_exception, tuple): - for exc in expected_exception: - if not isclass(exc): - raise TypeError(msg % type(exc)) - elif not isclass(expected_exception): - raise TypeError(msg % type(expected_exception)) + for exc in filterfalse(isclass, always_iterable(expected_exception)): + msg = ("exceptions must be old-style classes or" + " derived from BaseException, not %s") + raise TypeError(msg % type(exc)) message = "DID NOT RAISE {0}".format(expected_exception) match_expr = None diff --git a/setup.py b/setup.py index 30234d2cc..78f082913 100644 --- a/setup.py +++ b/setup.py @@ -60,6 +60,7 @@ def main(): 'six>=1.10.0', 'setuptools', 'attrs>=17.2.0', + 'more_itertools>=4.0.0', ] # if _PYTEST_SETUP_SKIP_PLUGGY_DEP is set, skip installing pluggy; # used by tox.ini to test with pluggy master From 14a9b1ec838fc1b2bb530458757c0bb9a67f164d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 28 Feb 2018 17:31:11 -0300 Subject: [PATCH 2/2] Add CHANGELOG for #3265 --- changelog/3265.trivial.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/3265.trivial.rst diff --git a/changelog/3265.trivial.rst b/changelog/3265.trivial.rst new file mode 100644 index 000000000..b4ad22ecf --- /dev/null +++ b/changelog/3265.trivial.rst @@ -0,0 +1 @@ +``pytest`` now depends on the `more_itertools `_ package.