diff --git a/changelog/4012.bugfix.rst b/changelog/4012.bugfix.rst deleted file mode 100644 index 11d8deef7..000000000 --- a/changelog/4012.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -``pytest.warn`` will capture previously-warned warnings in python2. Previously they were never raised. diff --git a/changelog/4102.bugfix.rst b/changelog/4102.bugfix.rst new file mode 100644 index 000000000..dd066c38d --- /dev/null +++ b/changelog/4102.bugfix.rst @@ -0,0 +1 @@ +``pytest.warn`` will capture previously-warned warnings in Python 2. Previously they were never raised. diff --git a/changelog/4102.feature.rst b/changelog/4102.feature.rst index b7916c841..ee43ddc24 100644 --- a/changelog/4102.feature.rst +++ b/changelog/4102.feature.rst @@ -1 +1,4 @@ Reimplement ``pytest.deprecated_call`` using ``pytest.warns`` so it supports the ``match='...'`` keyword argument. + +This has the side effect that ``pytest.deprecated_call`` now raises ``pytest.fail.Exception`` instead +of ``AssertionError``. diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index 592abdf5b..6ca1b0384 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -156,18 +156,18 @@ class WarningsRecorder(warnings.catch_warnings): if six.PY2: def warn(*args, **kwargs): - return self._warn(*args, **kwargs) + return self._saved_warn(*args, **kwargs) - warnings.warn, self._warn = warn, warnings.warn + warnings.warn, self._saved_warn = warn, warnings.warn return self def __exit__(self, *exc_info): if not self._entered: __tracebackhide__ = True raise RuntimeError("Cannot exit %r without entering first" % self) - # see above where `self.mp` is assigned + # see above where `self._saved_warn` is assigned if six.PY2: - warnings.warn = self._warn + warnings.warn = self._saved_warn super(WarningsRecorder, self).__exit__(*exc_info)