pytest_notebook.diffing module#

Diffing of notebooks.

pytest_notebook.diffing.diff_notebooks(initial: NotebookNode, final: NotebookNode, initial_path: str = '') List[DiffEntry][source]#

Compare two notebooks.

This is a simplified version of nbdime.diff_notebooks(), where we replace nbdime.diff_sequence_multilevel() with diff_sequence_simple() to diff the cell and output lists. diff_sequence_multilevel use ‘snakes’ computation, to guess where cells have been inserted/removed. However, this can lead to longer diffs, where cells with changed outputs are assigned as removed/inserted, rather than simply modified. Moreover, since we are comparing the same notebook before/after execution, we shouldn’t need to worry about insertions.

pytest_notebook.diffing.diff_sequence_simple(initial: Sequence, final: Sequence, path: str = '', config: DiffConfig | None = None) dict[source]#

Compute diff of two lists with configurable behaviour.

If the lists are of different lengths, we assume that items have been appended or removed from the end of the initial list.

pytest_notebook.diffing.diff_to_string(notebook: NotebookNode, diff_obj: dict, use_git: bool = True, use_diff: bool = True, use_color: bool = True, color_words: bool = False) str[source]#

Convert diff to formatted string.

Parameters:
  • use_git – use git for formatting diff/merge text output

  • use_diff – use diff/diff3 for formatting diff/merge text output

  • use_color – whether to prevent use of ANSI color code escapes for text output

  • color_words – whether to pass the –color-words flag to any internal calls to git diff

pytest_notebook.diffing.filter_diff(diff: List[DiffEntry], remove_paths: List[str], path: str = '') List[DiffEntry][source]#

Filter a notebook diff object, removing a list of paths.

Paths are joined by ‘/’ and may be starred, e.g. ‘/cells/*/outputs’.

pytest_notebook.diffing.star_path(path)[source]#

Replace integers and integer-strings in a path with * .