From b6fbdc2b1dfefddcd31f9cc8622fdd6cfba045e6 Mon Sep 17 00:00:00 2001 From: Alex Severin Date: Sat, 11 Jan 2025 03:50:32 +0300 Subject: [PATCH] skip readme tests instead of fail --- tests/test_readme.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/test_readme.py b/tests/test_readme.py index 4acce98..115ae61 100644 --- a/tests/test_readme.py +++ b/tests/test_readme.py @@ -1,14 +1,23 @@ +import pytest +import os from pathlib import Path Script = str -def test_readme() -> None: - readme_path = Path("./README.md") - scripts = parse_readme_code(readme_path, "```python\n", "```\n") - scripts += parse_readme_code(readme_path, "```py\n", "```\n") - assert len(scripts) > 0 +@pytest.mark.parametrize(["path"], [("./README.md",)]) +def test_readme(path: os.PathLike) -> None: + path = Path(path) + if not path.exists(): + pytest.skip(reason=f"{path} doesn't exist") + + text = path.read_text() + scripts = parse_md_scripts(text, "```python\n", "```\n") + scripts += parse_md_scripts(text, "```py\n", "```\n") + if len(scripts) == 0: + pytest.skip(reason=f"no scripts in {path}") + for script in scripts: print("\n# executing the following script") print(script) @@ -16,9 +25,7 @@ def test_readme() -> None: exec(script) -def parse_readme_code(path: Path, start_tag: str, end_tag) -> list[Script]: - assert path.exists() - text = path.read_text() +def parse_md_scripts(text: str, start_tag: str, end_tag) -> list[Script]: _, *sections = text.split(start_tag) scripts = [] for section in sections: