pytest_notebook.plugin module#

pytest plugin configuration.

For more information on writing pytest plugins see:

class pytest_notebook.plugin.JupyterNbCollector(*k, **kw)[source]#

Bases: File

This class represents a pytest collector object for Jupyter Notebook files.

A collector is associated with a .ipynb file and collects it for testing.

_abc_impl = <_abc._abc_data object>#
_nodeid#
_store#
collect()[source]#

Collect tests for the notebook.

config#

The pytest config object.

name#

A unique name within the scope of the parent node.

parent#

The parent collector node.

path#

Filesystem path where this node was collected from.

session#

The pytest session this node is part of.

class pytest_notebook.plugin.JupyterNbTest(*k, **kw)[source]#

Bases: Item

This class represents a pytest test invocation for a Jupyter Notebook file.

_abc_impl = <_abc._abc_data object>#
_nodeid#
_store#
config#

The pytest config object.

name#

A unique name within the scope of the parent node.

parent#

The parent collector node.

path#

Filesystem path where this node was collected from.

reportinfo()[source]#

Report location of item.

repr_failure(exc_info)[source]#

Handle exception raised by self.runtest().

Parameters:

exc_info – see https://docs.pytest.org/en/latest/reference.html#_pytest._code.ExceptionInfo

runtest()[source]#

Run the test.

session#

The pytest session this node is part of.

class pytest_notebook.plugin.NotSet[source]#

Bases: object

Class to indicate a configuration value was not set.

pytest_notebook.plugin._matches_pattern(file_path: Path, pattern: str) bool[source]#

Match a file against an fnmatch pattern.

Patterns containing a path separator are matched against the full path (relative patterns match any trailing path segments), otherwise against the file name (mirroring py.path.local.fnmatch).

pytest_notebook.plugin.gather_config_options(pytestconfig)[source]#

Gather all options, from command-line and ini file.

Note: command-line set options are prioritised over ini file ones.

pytest_notebook.plugin.gather_nbdime_ignore_config(pytestconfig)[source]#

Load diff-ignore paths from an nbdime_config.json file.

The (first) file is looked up in the current working directory, then the pytest root directory, and the result is cached for the session.

pytest_notebook.plugin.nb_regression(pytestconfig)[source]#

Fixture to execute a Jupyter Notebook, and test its output is as expected.

pytest_notebook.plugin.pytest_addoption(parser)[source]#

Add pytest commandline and configuration file options.

pytest_notebook.plugin.pytest_collect_file(file_path: Path, parent)[source]#

Collect Jupyter notebooks using the specified pytest hook.

pytest_notebook.plugin.pytest_report_header(config)[source]#

Add header information for pytest execution.

pytest_notebook.plugin.str2bool(string)[source]#

Convert a string representation of truth to True or False.

True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’. Raises ValueError if ‘val’ is anything else.

pytest_notebook.plugin.strip_quotes(string)[source]#

Strip quotes from string.

pytest_notebook.plugin.validate_diff_replace(pytestconfig)[source]#

Extract the nb_diff_replace option from the ini file.

This should be of the format:

nb_diff_replace =
    /cells/*/outputs \d{1,2}/\d{1,2}/\d{2,4} REPLACE_DATE
    /cells/*/outputs "\d{2}:\d{2}:\d{2}" "REPLACE_TIME"
pytest_notebook.plugin.validate_exec_env(pytestconfig)[source]#

Extract the nb_exec_env option from the ini file.

This should be a list of lines of the format KEY=VALUE:

nb_exec_env =
    MY_VAR=my_value
    PYTHONPATH=src