Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
davidovichmarcos committed Aug 16, 2024
1 parent 05d5dc1 commit f08bfa7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions nb-tests/test_notebooks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import re
import pathlib
from dataclasses import dataclass
import ee
import papermill
from papermill.execute import PapermillExecutionError
import pytest

try:
Expand Down Expand Up @@ -53,13 +55,14 @@ class Notebook:
ids=[nb.path.name for nb in ALL_NOTEBOOKS],
)
def test_notebooks(notebook: Notebook):
if notebook.raises: # these are the ones we expect to raise errors
with pytest.raises(PapermillExecutionError, match=re.escape(notebook.raises_match)):
papermill.execute_notebook(str(notebook.path), "./output.ipynb", kernel_name="venv")
pytest.xfail(f"Notebook {notebook.path} is known to fail with error {notebook.raises_match}")
try:
papermill.execute_notebook(str(notebook.path), "./output.ipynb", kernel_name="venv")
except Exception as e:
if notebook.raises: # these are the ones we expect to raise errors
pytest.xfail(f"Notebook {notebook.path} is known to fail with error {notebook.raises_match}")
else:
raise UnexecptedNotebookExecutionError(
f"{notebook.path.name=} not in {list(KNOWN_ERRORS_REGEXES)= } but execution errored. "
"This notebook is unexpectedly broken."
) from e
raise UnexecptedNotebookExecutionError(
f"{notebook.path.name=} not in {list(KNOWN_ERRORS_REGEXES)= } but execution errored. "
"This notebook is unexpectedly broken."
) from e

0 comments on commit f08bfa7

Please sign in to comment.