diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 7622139892..0d5a0fcf45 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -75,7 +75,7 @@ jobs: - name: Run example tests working-directory: autotest - run: pytest -v test_example_scripts.py -n=auto -s --durations=0 --keep-failed=.failed + run: pytest -v test_example_notebooks.py -n=auto -s --durations=0 --keep-failed=.failed env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/autotest/test_example_notebooks.py b/autotest/test_example_notebooks.py index ad59e1b1e2..04654a9648 100644 --- a/autotest/test_example_notebooks.py +++ b/autotest/test_example_notebooks.py @@ -44,6 +44,7 @@ def test_notebooks(notebook): pkg = re.findall("No module named '(.*)'", stderr)[0] pytest.skip(f"notebook requires package {pkg!r}") - assert returncode == 0, f"could not run {notebook}" - pprint(stdout) - pprint(stderr) + if returncode != 0: + pprint(stdout) + pprint(stderr) + raise ValueError(f"could not run {notebook}") diff --git a/autotest/test_example_scripts.py b/autotest/test_example_scripts.py deleted file mode 100644 index 56909c53fa..0000000000 --- a/autotest/test_example_scripts.py +++ /dev/null @@ -1,48 +0,0 @@ -import re -from pprint import pprint - -import pytest -from flaky import flaky -from modflow_devtools.misc import is_in_ci, run_cmd, run_py_script - -from autotest.conftest import get_project_root_path - - -def get_scripts(pattern=None, exclude=None): - prjroot = get_project_root_path() - nbpaths = [ - str(p) - for p in (prjroot / ".docs" / "Notebooks").glob("*.py") - if pattern is None or pattern in p.name - ] - - # sort for pytest-xdist: workers must collect tests in the same order - return sorted( - [p for p in nbpaths if not exclude or not any(e in p for e in exclude)] - ) - - -@flaky(max_runs=3) -@pytest.mark.slow -@pytest.mark.example -@pytest.mark.parametrize( - "script", - get_scripts(pattern="tutorial", exclude=["mf6_lgr"]) - + get_scripts(pattern="example"), -) -def test_scripts(script): - stdout, stderr, returncode = run_py_script(script, verbose=True) - - # allow notebooks to fail for lack of optional dependencies in local runs, - # expect all dependencies to be present and notebooks to pass in ci tests. - if returncode != 0 and not is_in_ci(): - if "Missing optional dependency" in stderr: - pkg = re.findall("Missing optional dependency '(.*)'", stderr)[0] - pytest.skip(f"notebook requires optional dependency {pkg!r}") - elif "No module named " in stderr: - pkg = re.findall("No module named '(.*)'", stderr)[0] - pytest.skip(f"notebook requires package {pkg!r}") - - assert returncode == 0, f"could not run {script}" - pprint(stdout) - pprint(stderr)