Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter warnings from AssertionRewritingHook when exec'ing module #12248

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/_pytest/assertion/rewrite.py
Expand Up @@ -29,6 +29,7 @@
from typing import Tuple
from typing import TYPE_CHECKING
from typing import Union
import warnings

from _pytest._io.saferepr import DEFAULT_REPR_MAX_SIZE
from _pytest._io.saferepr import saferepr
Expand Down Expand Up @@ -175,7 +176,9 @@ def exec_module(self, module: types.ModuleType) -> None:
self._writing_pyc = False
else:
state.trace(f"found cached rewritten pyc for {fn}")
exec(co, module.__dict__)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
exec(co, module.__dict__)

def _early_rewrite_bailout(self, name: str, state: "AssertionState") -> bool:
"""A fast way to get out of rewriting modules.
Expand Down Expand Up @@ -859,8 +862,6 @@ def visit_Assert(self, assert_: ast.Assert) -> List[ast.stmt]:
the expression is false.
"""
if isinstance(assert_.test, ast.Tuple) and len(assert_.test.elts) >= 1:
import warnings

from _pytest.warning_types import PytestAssertRewriteWarning

# TODO: This assert should not be needed.
Expand Down