Skip to content

Commit 084d756

Browse files
authored
Merge pull request #11143 from tushar-deepsource/patch-1
2 parents d7dbadb + cb732f7 commit 084d756

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

Diff for: AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ Tomer Keren
374374
Tony Narlock
375375
Tor Colvin
376376
Trevor Bekolay
377+
Tushar Sadhwani
377378
Tyler Goodlet
378379
Tzu-ping Chung
379380
Vasily Kuznetsov

Diff for: changelog/11146.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Prevent constants at the top of file from being detected as docstrings.

Diff for: src/_pytest/assertion/rewrite.py

+1
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ def run(self, mod: ast.Module) -> None:
676676
expect_docstring
677677
and isinstance(item, ast.Expr)
678678
and isinstance(item.value, ast.Constant)
679+
and isinstance(item.value.value, str)
679680
):
680681
doc = item.value.value
681682
if self.is_rewrite_disabled(doc):

Diff for: testing/test_assertrewrite.py

+14
Original file line numberDiff line numberDiff line change
@@ -2042,3 +2042,17 @@ def test_max_increased_verbosity(self, pytester: Pytester) -> None:
20422042
self.create_test_file(pytester, DEFAULT_REPR_MAX_SIZE * 10)
20432043
result = pytester.runpytest("-vv")
20442044
result.stdout.no_fnmatch_line("*xxx...xxx*")
2045+
2046+
2047+
class TestIssue11140:
2048+
def test_constant_not_picked_as_module_docstring(self, pytester: Pytester) -> None:
2049+
pytester.makepyfile(
2050+
"""\
2051+
0
2052+
2053+
def test_foo():
2054+
pass
2055+
"""
2056+
)
2057+
result = pytester.runpytest()
2058+
assert result.ret == 0

0 commit comments

Comments
 (0)