Skip to content

Commit ff23a49

Browse files
committed
fix re-emitting to wrong module
1 parent 9cc6b50 commit ff23a49

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/_pytest/recwarn.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pprint import pformat
77
import re
8+
import sys
89
from types import TracebackType
910
from typing import Any
1011
from typing import Callable
@@ -327,12 +328,17 @@ def found_str() -> str:
327328
# Whether or not any warnings matched, we want to re-emit all unmatched warnings.
328329
for w in self:
329330
if not self.matches(w):
331+
module = next(
332+
k
333+
for k, v in sys.modules.items()
334+
if getattr(v, "__file__", None) == w.filename
335+
)
330336
warnings.warn_explicit(
331337
message=w.message,
332338
category=w.category,
333339
filename=w.filename,
334340
lineno=w.lineno,
335-
module=w.__module__,
341+
module=module,
336342
source=w.source,
337343
)
338344

0 commit comments

Comments
 (0)