Skip to content

Commit 8a6446d

Browse files
committed
re_emit all unmatched warnings
1 parent 68fef68 commit 8a6446d

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/_pytest/recwarn.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,10 @@ def __exit__(
290290
def found_str():
291291
return pformat([record.message for record in self], indent=2)
292292

293-
def re_emit_without(exc=None):
293+
def re_emit(remove=None):
294294
exceptions = self._list.copy()
295-
if exc:
296-
exceptions.remove(exc)
297-
else:
298-
# remove the first exception that matches the expected warning
299-
for r in exceptions:
300-
if issubclass(r.category, self.expected_warning):
301-
exceptions.remove(r)
302-
break
295+
if remove:
296+
exceptions.remove(remove)
303297

304298
for e in exceptions:
305299
warnings.warn_explicit(
@@ -324,7 +318,7 @@ def re_emit_without(exc=None):
324318
for r in self:
325319
if issubclass(r.category, self.expected_warning):
326320
if re.compile(self.match_expr).search(str(r.message)):
327-
re_emit_without(r)
321+
re_emit(r)
328322
break
329323
else:
330324
fail(
@@ -333,6 +327,5 @@ def re_emit_without(exc=None):
333327
Regex: {self.match_expr}
334328
Emitted warnings: {found_str()}"""
335329
)
336-
# can add warnings.warn for all other warn objects besides this here
337330
else:
338-
re_emit_without()
331+
re_emit()

0 commit comments

Comments
 (0)