Fix assert rewriting with assignment expressions (#11414)

Fixes #11239
This commit is contained in:
Marc Mueller
2023-09-09 14:09:31 +02:00
committed by GitHub
parent dd7beb39d6
commit 7259e8db98
4 changed files with 63 additions and 14 deletions

View File

@@ -1543,6 +1543,27 @@ class TestIssue11028:
result.stdout.fnmatch_lines(["*assert 4 > 5", "*where 5 = add_one(4)"])
class TestIssue11239:
def test_assertion_walrus_different_test_cases(self, pytester: Pytester) -> None:
"""Regression for (#11239)
Walrus operator rewriting would leak to separate test cases if they used the same variables.
"""
pytester.makepyfile(
"""
def test_1():
state = {"x": 2}.get("x")
assert state is not None
def test_2():
db = {"x": 2}
assert (state := db.get("x")) is not None
"""
)
result = pytester.runpytest()
assert result.ret == 0
@pytest.mark.skipif(
sys.maxsize <= (2**31 - 1), reason="Causes OverflowError on 32bit systems"
)