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

Fix for single line docstrings #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pytest_examples/find_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def find_examples(*paths: str | Path, skip: bool = False) -> Iterable[CodeExampl
group = uuid4()
if path.suffix == '.py':
code = path.read_text('utf-8')
for m_docstring in re.finditer(r'(^ *)(r?""")(.+?)\1"""', code, flags=re.M | re.S):
for m_docstring in re.finditer(r'(^ *)(r?""")(.+?)"""', code, flags=re.M | re.S):
start_line = code[: m_docstring.start()].count('\n')
docstring = m_docstring.group(3)
index_offset = m_docstring.start() + len(m_docstring.group(1)) + len(m_docstring.group(2))
Expand Down
5 changes: 5 additions & 0 deletions tests/test_find_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ def test_find_index_markdown(tmp_path):
def test_find_index_python(tmp_path):
# language=Python
code = '''
def foo():
"""Single line docstring"""
pass


def func_a():
"""
prefix.
Expand Down