pytest_notebook.normalizers module#

Plugins to normalize notebooks before diffing.

Unlike post-processors (which are applied only to the notebook produced by execution), normalizers are applied to both the stored and the executed notebook, before they are diffed. They are intended to remove insignificant differences in outputs, such as ANSI colour codes, timestamps and memory addresses.

All functions should take a notebook as input, and output a new notebook, without mutating the input notebook.

pytest_notebook.normalizers.collapse_whitespace(notebook: NotebookNode) NotebookNode[source]#

Collapse runs of spaces/tabs, and remove trailing whitespace, in text outputs.

This is useful for e.g. pandas DataFrame text representations, whose column-alignment whitespace can change between pandas versions.

pytest_notebook.normalizers.list_normalizer_names()[source]#

List entry point names for diff normalizers.

pytest_notebook.normalizers.load_normalizer(name: str)[source]#

Get a diff normalizer for an entry point name.

pytest_notebook.normalizers.mask_memory_addresses(notebook: NotebookNode) NotebookNode[source]#

Replace memory addresses (0x…) in text outputs and tracebacks.

pytest_notebook.normalizers.mask_timestamps(notebook: NotebookNode) NotebookNode[source]#

Replace dates (YYYY-MM-DD) and times (HH:MM:SS) in text outputs.

pytest_notebook.normalizers.mask_uuids(notebook: NotebookNode) NotebookNode[source]#

Replace UUIDs in text outputs and tracebacks.

pytest_notebook.normalizers.strip_ansi(notebook: NotebookNode) NotebookNode[source]#

Remove ANSI escape sequences from text outputs and tracebacks.