Skip to content

Commit 617efcc

Browse files
committed
Speedup test to cache rglob once
1 parent d8ee755 commit 617efcc

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

tests/test_all_notebooks_are_tested.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
import os
33
from utils_for_tests import get_all_notebooks, ROOT_DIRECTORY, resolve_notebook_path
44

5+
TESTS_FOLDER = ROOT_DIRECTORY / "tests"
6+
7+
8+
@pytest.fixture
9+
def all_test_file_names() -> list[str]:
10+
return [i.name for i in TESTS_FOLDER.rglob("test_*.py")]
11+
512

613
@pytest.mark.parametrize("notebook_name", map(os.path.basename, get_all_notebooks()))
7-
def test_is_notebook_tested(notebook_name: str):
14+
def test_is_notebook_tested(notebook_name: str, all_test_file_names: list[str]):
815
if not _should_skip_notebook(notebook_name):
916
expected_test_name = f"test_{notebook_name[:-6]}.py" # [:-6] removes ".ipynb"
10-
assert list(ROOT_DIRECTORY.rglob(expected_test_name)), (
17+
assert expected_test_name in all_test_file_names, (
1118
f"No test was found for '{notebook_name}'. Expecting to find '{expected_test_name}'"
1219
f"\nIt is common for notebooks tests to be placed in 'ROOT_FOLDER/tests/notebooks/{expected_test_name}'."
1320
"\nNote: tests are auto-generated when using pre-commit."

0 commit comments

Comments
 (0)