Skip to content

Commit af979fd

Browse files
committed
Test that all notebooks are tested
1 parent 44e58d3 commit af979fd

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

tests/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
LAST = "test_last.py"
4+
5+
6+
def pytest_collection_modifyitems(
7+
items: list[pytest.Function],
8+
) -> list[pytest.Function]:
9+
return [i for i in items if i.module.__name__ != LAST] + [
10+
i for i in items if i.module.__name__ == LAST
11+
]

tests/test_last.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from tests.utils_for_testbook import TESTED_NOTEBOOKS
2+
from tests.utils_for_tests import iterate_notebook_names
3+
4+
5+
def test_are_all_notebooks_tested():
6+
assert sorted(TESTED_NOTEBOOKS) == sorted(iterate_notebook_names())

tests/utils_for_testbook.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
_PATCHED = False
2020

21+
TESTED_NOTEBOOKS: list[str] = []
22+
2123

2224
def wrap_testbook(notebook_name: str, timeout_seconds: float = 10) -> Callable:
2325
def inner_decorator(func: Callable) -> Any:
@@ -29,6 +31,7 @@ def inner_decorator(func: Callable) -> Any:
2931
testbook(notebook_path, execute=True, timeout=timeout_seconds),
3032
_build_cd_decorator(notebook_path),
3133
_build_skip_decorator(notebook_path),
34+
_build_mark_as_tested(notebook_name),
3235
]:
3336
func = decorator(func)
3437
return func
@@ -62,6 +65,19 @@ def _build_skip_decorator(notebook_path: str) -> Callable:
6265
)
6366

6467

68+
def _build_mark_as_tested(notebook_name: str) -> Callable:
69+
def mark_as_tested_decorator(func: Callable) -> Any:
70+
def inner(*args: Any, **kwargs: Any) -> Any:
71+
try:
72+
func(*args, **kwargs)
73+
finally:
74+
TESTED_NOTEBOOKS.append(notebook_name)
75+
76+
return inner
77+
78+
return mark_as_tested_decorator
79+
80+
6581
def _patch_testbook() -> None:
6682
global _PATCHED
6783

0 commit comments

Comments
 (0)