Skip to content

Commit c9cab73

Browse files
committed
Add master test script for all usage example files
1 parent a471138 commit c9cab73

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎client/python/examples/all.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is like a master test. Runs all the examples
2+
# Not exactly the purpose of the examples dir,
3+
# but helps in checking if any code updates haven't broken the API
4+
5+
from pathlib import Path
6+
import subprocess
7+
import pytest
8+
9+
# Didn't know I could do this with pytest, so cool
10+
# Just run: pytest ./master_examples.py -v
11+
12+
EXAMPLES_DIR = Path(__file__).parent
13+
example_files = sorted(EXAMPLES_DIR.glob("*_usage.py"))
14+
15+
16+
@pytest.mark.parametrize(
17+
"script_path",
18+
example_files,
19+
ids=lambda p: p.stem, # or p.name
20+
)
21+
def test(script_path):
22+
"""Run all example scripts to check if they crash or not"""
23+
result = subprocess.run(
24+
["python3", str(script_path)],
25+
capture_output=True,
26+
text=True
27+
)
28+
assert result.returncode == 0, (
29+
f"Script {script_path} failed with stderr:\n{result.stderr}"
30+
)

0 commit comments

Comments
 (0)