Skip to content

Commit ba4263d

Browse files
committed
13403: Disable assertion rewriting for external modules - add test for plugins
1 parent 5efcb78 commit ba4263d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

testing/test_assertrewrite.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ def test_rewrites_plugin_as_a_package(self, pytester: Pytester) -> None:
371371
pytester.makeconftest('pytest_plugins = ["plugin"]')
372372
pytester.makepyfile("def test(special_asserter): special_asserter(1, 2)\n")
373373
result = pytester.runpytest()
374+
374375
result.stdout.fnmatch_lines(["*assert 1 == 2*"])
375376

376377
def test_honors_pep_235(self, pytester: Pytester, monkeypatch) -> None:
@@ -1981,11 +1982,11 @@ def test_simple_failure():
19811982
assert hook.find_spec("file") is None
19821983

19831984

1984-
def test_assert_correct_for_conftfest(
1985+
def test_assert_rewrite_correct_for_conftfest(
19851986
self, pytester: Pytester, hook: AssertionRewritingHook, monkeypatch
19861987
) -> None:
19871988
"""
1988-
Conftest is always rewritten regardless of the working dir
1989+
Conftest is always rewritten regardless of the root dir
19891990
"""
19901991
pytester.makeconftest(
19911992
"""
@@ -2004,9 +2005,12 @@ def fix(): return 1
20042005
assert hook.find_spec("conftest") is not None
20052006

20062007

2007-
def test_assert_excluded_rewrite_for_plugins(
2008+
def test_assert_rewrite_correct_for_plugins(
20082009
self, pytester: Pytester, hook: AssertionRewritingHook, monkeypatch
20092010
) -> None:
2011+
"""
2012+
Plugins has always been rewritten regardless of the root dir
2013+
"""
20102014
pkgdir = pytester.mkpydir("plugin")
20112015
pkgdir.joinpath("__init__.py").write_text(
20122016
"import pytest\n"
@@ -2017,10 +2021,10 @@ def test_assert_excluded_rewrite_for_plugins(
20172021
" return special_assert\n",
20182022
encoding="utf-8",
20192023
)
2020-
pytester.makeconftest('pytest_plugins = ["plugin"]')
2024+
hook.mark_rewrite("plugin")
20212025
rootpath = f"{os.getcwd()}/tests"
20222026
if not os.path.exists(rootpath):
2023-
mkdir(rootpath)
2027+
mkdir(rootpath)
20242028
monkeypatch.chdir(rootpath)
20252029
with mock.patch.object(hook, "fnpats", ["*.py"]):
20262030
assert hook.find_spec("plugin") is not None

0 commit comments

Comments
 (0)