Skip to content

Commit 5116841

Browse files
committed
13403: Disable assertion rewriting for external modules - refactor AssertionStatus
1 parent edcf484 commit 5116841

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

testing/test_assertrewrite.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from _pytest.assertion.rewrite import _get_maxsize_for_saferepr
3131
from _pytest.assertion.rewrite import _saferepr
3232
from _pytest.assertion.rewrite import AssertionRewritingHook
33+
from _pytest.assertion.rewrite import assertstate_key
3334
from _pytest.assertion.rewrite import get_cache_dir
3435
from _pytest.assertion.rewrite import PYC_TAIL
3536
from _pytest.assertion.rewrite import PYTEST_TAG
@@ -2002,7 +2003,7 @@ def test_simple_failure():
20022003
assert hook.find_spec("file") is not None
20032004
assert self.find_spec_calls == ["file"]
20042005

2005-
def test_assert_rewrites_only_rootpath(
2006+
def test_assert_rewrites_only_invocation_path(
20062007
self, pytester: Pytester, hook: AssertionRewritingHook, monkeypatch
20072008
) -> None:
20082009
"""Do not rewrite assertions in tests outside `AssertState.rootpath` (#13403)."""
@@ -2014,21 +2015,19 @@ def test_simple_failure():
20142015
"""
20152016
}
20162017
)
2018+
20172019
with mock.patch.object(hook, "fnpats", ["*.py"]):
20182020
assert hook.find_spec("file") is not None
20192021

2020-
rootpath = f"{os.getcwd()}/tests"
2021-
if not os.path.exists(rootpath):
2022-
mkdir(rootpath)
2022+
invocation_path = f"{os.getcwd()}/tests"
2023+
if not os.path.exists(invocation_path):
2024+
mkdir(invocation_path)
20232025
monkeypatch.setattr(
2024-
pytester._request.config,
2025-
"invocation_params",
2026-
Config.InvocationParams(
2027-
args=(),
2028-
plugins=(),
2029-
dir=Path(rootpath),
2030-
),
2026+
pytester._request.config.stash[assertstate_key],
2027+
"invocation_path",
2028+
invocation_path,
20312029
)
2030+
20322031
with mock.patch.object(hook, "fnpats", ["*.py"]):
20332032
assert hook.find_spec("file") is None
20342033

0 commit comments

Comments
 (0)