diff --git a/pytest_examples/lint.py b/pytest_examples/lint.py index ccd833e..9575264 100644 --- a/pytest_examples/lint.py +++ b/pytest_examples/lint.py @@ -90,4 +90,5 @@ def replace_at_line(match: re.Match) -> str: offset = re.sub(r'\d+', lambda m: str(int(m.group(0)) + example.start_line), match.group(2)) return f'{match.group(1)}{offset}{match.group(3)}' + # we could add `.replace(' ', 'ยท')` to make white space easier to understand return re.sub(r'^(@@\s*)(.*)(\s*@@)$', replace_at_line, diff, flags=re.M) diff --git a/pytest_examples/run_code.py b/pytest_examples/run_code.py index 7a74e3e..e4f081d 100644 --- a/pytest_examples/run_code.py +++ b/pytest_examples/run_code.py @@ -157,7 +157,7 @@ def __exit__(self, *args) -> None: def check_print_statements(self, example: CodeExample) -> None: with_prints = self._insert_print_statements(example) # we check against the raw `with_prints` and `with_prints` with trailing whitespace removed - if example.source != with_prints and example.source != re.sub(r'\s+\n', '\n', with_prints): + if example.source != with_prints and example.source != re.sub(r'[ \t]+\n', '\n', with_prints): diff = code_diff(example, with_prints) pytest.fail(f'Print output changed code:\n{indent(diff, " ")}', pytrace=False) diff --git a/tests/test_run_examples.py b/tests/test_run_examples.py index c7423f2..1b1ca08 100644 --- a/tests/test_run_examples.py +++ b/tests/test_run_examples.py @@ -314,6 +314,7 @@ def test_print_check_spaces(pytester: pytest.Pytester): ```py # note trailing space + print('hello ') #> hello ```""",