pytest_notebook.nb_regression module¶
Jupyter Notebook Regression Test Class.
-
exception
pytest_notebook.nb_regression.NBRegressionError[source]¶ Bases:
ExceptionException to signal a regression test fail.
-
class
pytest_notebook.nb_regression.NBRegressionFixture(exec_notebook: bool = True, exec_cwd: Optional[str] = None, exec_allow_errors: bool = False, exec_timeout: int = 120, coverage: bool = False, cov_config: Optional[str] = None, cov_source: Union[str, Tuple[str]] = None, cov_merge: Optional[coverage.control.Coverage] = None, post_processors: tuple = ('coalesce_streams', ), process_resources: dict = NOTHING, diff_replace: tuple = (), diff_ignore: tuple = ('/cells/*/outputs/*/traceback', ), diff_use_color: bool = True, diff_color_words: bool = False, force_regen: bool = False)[source]¶ Bases:
objectClass to perform Jupyter Notebook Regression tests.
- Parameters
exec_notebook (bool) – Create a new notebook, by executing all cells in the original notebook This value is accessible, after initialization, via the
exec_notebookattribute. Default: Trueexec_cwd (str, NoneType) – Path to the directory which the notebook will run in (defaults to directory of notebook). This value is accessible, after initialization, via the
exec_cwdattribute. Default: Noneexec_allow_errors (bool) – Do not stop execution after the first unexpected exception (where cell is not tagged
raises-exception). This value is accessible, after initialization, via theexec_allow_errorsattribute. Default: Falseexec_timeout (int) – The maximum time to wait (in seconds) for execution of each cell. This value is accessible, after initialization, via the
exec_timeoutattribute. Default: 120coverage (bool) – Record coverage data, with coverage.py. This value is accessible, after initialization, via the
coverageattribute. Default: Falsecov_config (str, NoneType) – Determines what coverage configuration file to read. This value is accessible, after initialization, via the
cov_configattribute. Default: Nonecov_source (str, Tuple[str]) – A list of file paths or package names to measure coverage for. This value is accessible, after initialization, via the
cov_sourceattribute. Default: Nonecov_merge (coverage.control.Coverage, NoneType) – A coverage.Coverage instance, to merge coverage results with. This value is accessible, after initialization, via the
cov_mergeattribute. Default: Nonepost_processors (tuple) – post-processors to apply to the new workbook, relating to entry points in the ‘nbreg.post_proc’ group This value is accessible, after initialization, via the
post_processorsattribute. Default: (‘coalesce_streams’,)process_resources (dict) – Resources to parse to processor functions. This value is accessible, after initialization, via the
process_resourcesattribute. Default: Factory(factory=<class ‘dict’>, takes_self=False)diff_replace (tuple) – A list of regex replacements to apply before diffing, e.g.
[('/cells/*/outputs', '\d{2,4}-\d{1,2}-\d{1,2}', 'DATE-STAMP')]. This value is accessible, after initialization, via thediff_replaceattribute. Default: ()diff_ignore (tuple) – List of diff paths to ignore, e.g. ‘/cells/1/outputs’ or ‘/cells/*/metadata’. This value is accessible, after initialization, via the
diff_ignoreattribute. Default: (‘/cells//outputs//traceback’,)diff_use_color (bool) – Use ANSI color code escapes for text output. This value is accessible, after initialization, via the
diff_use_colorattribute. Default: Truediff_color_words (bool) – Highlight changed words using only colors. This value is accessible, after initialization, via the
diff_color_wordsattribute. Default: Falseforce_regen (bool) – Re-generate notebook files, if no unexpected execution errors, and an output path has been supplied. This value is accessible, after initialization, via the
force_regenattribute. Default: False
-
check(path: Union[TextIO, str], raise_errors: bool = True) → pytest_notebook.nb_regression.NBRegressionResult[source]¶ Execute the Notebook and compare its initial vs. final contents.
if
force_regenis True, the new notebook will be written topathif
raise_errorsis True:- Raises
nbconvert.preprocessors.CellExecutionError – if error in execution
NBConfigValidationError – if the notebook metadata is invalid
NBRegressionError – if diffs present
- Return type
-
class
pytest_notebook.nb_regression.NBRegressionResult(nb_initial: nbformat.notebooknode.NotebookNode, nb_final: nbformat.notebooknode.NotebookNode, diff_full: List[nbdime.diff_format.DiffEntry], diff_filtered: List[nbdime.diff_format.DiffEntry], diff_string: str, process_resources: dict = NOTHING)[source]¶ Bases:
objectA class to store the result of
NBRegressionFixture.check.- Parameters
nb_initial (nbformat.notebooknode.NotebookNode) – Initial notebook. This value is accessible, after initialization, via the
nb_initialattribute.nb_final (nbformat.notebooknode.NotebookNode) – Notebook after execution and post-processing. This value is accessible, after initialization, via the
nb_finalattribute.diff_full (List[nbdime.diff_format.DiffEntry]) – Full diff of initial/final notebooks. This value is accessible, after initialization, via the
diff_fullattribute.diff_filtered (List[nbdime.diff_format.DiffEntry]) – Diff of initial/final notebooks, filtered according to the parsed configuration. This value is accessible, after initialization, via the
diff_filteredattribute.diff_string (str) – The formatte string of diff_filtered. This value is accessible, after initialization, via the
diff_stringattribute.process_resources (dict) – Resources returned from notebook processors. This value is accessible, after initialization, via the
process_resourcesattribute. Default: Factory(factory=<class ‘dict’>, takes_self=False)
-
diff_filtered¶
-
diff_full¶
-
diff_string¶
-
nb_final¶
-
nb_initial¶
-
process_resources¶