Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure the docstring is a string #11143

Merged
merged 7 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ def run(self, mod: ast.Module) -> None:
doc = item.value.value
else:
doc = item.value.s
if not isinstance(doc, str):
return
if self.is_rewrite_disabled(doc):
return
expect_docstring = False
Expand Down
14 changes: 14 additions & 0 deletions testing/test_assertrewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2055,3 +2055,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