Skip to main content

A pytest plugin for testing Jupyter libraries and extensions.

Project description

pytest-jupyter

A set of pytest plugins for Jupyter libraries and extensions.

Build Status codecov

Basic Usage

First, install pytest-jupyter from PyPI using pip:

pip install pytest-jupyter

This installs the basic pytest-jupyter package that includes fixture definitions for the various Jupyter-based pytest plugins.

To use one of these plugins, you'll also need to install their dependencies. This requires a second pip install call. For example, if you'd like to use the jupyter_server plugin, you'll need to call:

pip install "pytest-jupyter[server]"

This should install everything you need for the plugin to work.

To use a plugin, add it to the pytest_plugins list in the conftest.py of your project's root test directory.

# inside the conftest.py

pytest_plugins = ["pytest_jupyter.jupyter_server"]

This library includes an echo_kernel, which is useful to speed up testing. You must have either "pytest-jupyter[server]" or "pytest-jupyter[client]" installed to use the echo kernel.

The pytest_jupyter.jupyter_client plugin provides an installed echo_kernel_spec as a fixture, and a start_kernel fixture that provides a factory function that starts a kernel using the echo kernel by default.

The server fixures use the echo kernel by default. To override this behavior, override the jp_server_config fixture and add the following config:

{
    "MultiKernelManager": {
        "default_kernel_name": "<desired_kernel_name"
    }
}

All fixtures inside the plugin (e.g. jupyter_server) will be available to all of your project's unit tests. You can use a fixtures by passing it as an argument to your unit test function:

async def test_jupyter_server_api(jp_fetch):
    # Send request to a temporary Jupyter Server Web Application
    response = await jp_fetch("api/spec.yml")

    # Confirm that the request is successful.
    assert response.code == 200

You can list the fixtures for a given plugin using the --fixtures argument from the pytest command line interface:

pytest --fixtures -p pytest_jupyter.jupyter_server

or by calling the pytest --fixtures where the plugin is listed in the pytest_plugins variable of a given test directory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_jupyter-0.2.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_jupyter-0.2.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest_jupyter-0.2.0.tar.gz.

File metadata

  • Download URL: pytest_jupyter-0.2.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for pytest_jupyter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9360fc07f2afc9fde0df5d303ed629c41494fb0ec0fa6d45d85fbef1b912dea9
MD5 91a4253d46365a40dc8fa4dbd4992c8c
BLAKE2b-256 265fefe31e2d22b5499cd2d0792a8ba1fa2bee244e06a65cd8162b278282cb2f

See more details on using hashes here.

File details

Details for the file pytest_jupyter-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_jupyter-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for pytest_jupyter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3875849054c8621d7ae707ca1dd820535b144cabac655db7cfb51d55e88314fc
MD5 8cea11f9cf3fbdb60d1dcfd666014c0d
BLAKE2b-256 3ea325a545752d20786a544b9d68f60f1ba7506fdbd2fc43bcb039284b00309d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page