From df3b5557d176744967e1fef42c25c765794d2a32 Mon Sep 17 00:00:00 2001 From: Victor Maryama Date: Wed, 9 Jan 2019 12:51:04 +0100 Subject: [PATCH] Reseting entered state in WarningsRecorder (fixes 4617) --- src/_pytest/recwarn.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index f39f7aee7..da408a892 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -192,6 +192,10 @@ class WarningsRecorder(warnings.catch_warnings): warnings.warn = self._saved_warn super(WarningsRecorder, self).__exit__(*exc_info) + # Built-in catch_warnings does not reset entered state so we do it + # manually here for this context manager to become reusable + self._entered = False + class WarningsChecker(WarningsRecorder): def __init__(self, expected_warning=None, match_expr=None):