Skip to content

Commit

Permalink
Merge pull request #11143 from tushar-deepsource/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD authored Jul 4, 2023
2 parents d7dbadb + cb732f7 commit 084d756
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ Tomer Keren
Tony Narlock
Tor Colvin
Trevor Bekolay
Tushar Sadhwani
Tyler Goodlet
Tzu-ping Chung
Vasily Kuznetsov
Expand Down
1 change: 1 addition & 0 deletions changelog/11146.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Prevent constants at the top of file from being detected as docstrings.
1 change: 1 addition & 0 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ def run(self, mod: ast.Module) -> None:
expect_docstring
and isinstance(item, ast.Expr)
and isinstance(item.value, ast.Constant)
and isinstance(item.value.value, str)
):
doc = item.value.value
if self.is_rewrite_disabled(doc):
Expand Down
14 changes: 14 additions & 0 deletions testing/test_assertrewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2042,3 +2042,17 @@ def test_max_increased_verbosity(self, pytester: Pytester) -> None:
self.create_test_file(pytester, DEFAULT_REPR_MAX_SIZE * 10)
result = pytester.runpytest("-vv")
result.stdout.no_fnmatch_line("*xxx...xxx*")


class TestIssue11140:
def test_constant_not_picked_as_module_docstring(self, pytester: Pytester) -> None:
pytester.makepyfile(
"""\
0
def test_foo():
pass
"""
)
result = pytester.runpytest()
assert result.ret == 0

0 comments on commit 084d756

Please sign in to comment.