Coverage for test_examples.py: 93%

1 import os

2 import subprocess

3 import sys

4 from glob import glob

5 from pathlib import Path

6

7 import pytest

8

9

10 def get_examples():

11 # Where are we? --> __file__

12 # Move three up.

13 path = Path(__file__).parent.parent.parent

14 relpath = Path(os.path.relpath(path, os.getcwd())) / "examples/**/*.py"

15 examples = [f for f in glob(str(relpath)) if f.endswith(".py")]

16 return examples

17

18

19@pytest.mark.example

20@pytest.mark.parametrize("example", get_examples())

21 def test_example(example):

22 subprocess.run([sys.executable, example], check=True)