Skip to content

Commit d5eb2a6

Browse files
committed
13403: Disable assertion rewriting for external modules - add test for plugins
1 parent 0015d0a commit d5eb2a6

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
@@ -373,6 +373,7 @@ def test_rewrites_plugin_as_a_package(self, pytester: Pytester) -> None:
373373
pytester.makeconftest('pytest_plugins = ["plugin"]')
374374
pytester.makepyfile("def test(special_asserter): special_asserter(1, 2)\n")
375375
result = pytester.runpytest()
376+
376377
result.stdout.fnmatch_lines(["*assert 1 == 2*"])
377378

378379
def test_honors_pep_235(self, pytester: Pytester, monkeypatch) -> None:
@@ -1999,11 +2000,11 @@ def test_simple_failure():
19992000
assert hook.find_spec("file") is None
20002001

20012002

2002-
def test_assert_correct_for_conftfest(
2003+
def test_assert_rewrite_correct_for_conftfest(
20032004
self, pytester: Pytester, hook: AssertionRewritingHook, monkeypatch
20042005
) -> None:
20052006
"""
2006-
Conftest is always rewritten regardless of the working dir
2007+
Conftest is always rewritten regardless of the root dir
20072008
"""
20082009
pytester.makeconftest(
20092010
"""
@@ -2022,9 +2023,12 @@ def fix(): return 1
20222023
assert hook.find_spec("conftest") is not None
20232024

20242025

2025-
def test_assert_excluded_rewrite_for_plugins(
2026+
def test_assert_rewrite_correct_for_plugins(
20262027
self, pytester: Pytester, hook: AssertionRewritingHook, monkeypatch
20272028
) -> None:
2029+
"""
2030+
Plugins has always been rewritten regardless of the root dir
2031+
"""
20282032
pkgdir = pytester.mkpydir("plugin")
20292033
pkgdir.joinpath("__init__.py").write_text(
20302034
"import pytest\n"
@@ -2035,10 +2039,10 @@ def test_assert_excluded_rewrite_for_plugins(
20352039
" return special_assert\n",
20362040
encoding="utf-8",
20372041
)
2038-
pytester.makeconftest('pytest_plugins = ["plugin"]')
2042+
hook.mark_rewrite("plugin")
20392043
rootpath = f"{os.getcwd()}/tests"
20402044
if not os.path.exists(rootpath):
2041-
mkdir(rootpath)
2045+
mkdir(rootpath)
20422046
monkeypatch.chdir(rootpath)
20432047
with mock.patch.object(hook, "fnpats", ["*.py"]):
20442048
assert hook.find_spec("plugin") is not None

0 commit comments

Comments
 (0)