From ee6bee221390fadec9c0f6d80ef5ba28d1eeb295 Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Fri, 15 Nov 2024 15:17:12 +0200 Subject: [PATCH] Fix for single line docstrings (#21) Co-authored-by: Samuel Colvin --- pytest_examples/find_examples.py | 2 +- tests/test_find_examples.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pytest_examples/find_examples.py b/pytest_examples/find_examples.py index 18c4ed8..9f6523f 100644 --- a/pytest_examples/find_examples.py +++ b/pytest_examples/find_examples.py @@ -129,7 +129,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)) diff --git a/tests/test_find_examples.py b/tests/test_find_examples.py index 2751137..4e99a4e 100644 --- a/tests/test_find_examples.py +++ b/tests/test_find_examples.py @@ -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.