Skip to main content

A reusable JupyterHub pytest plugin

Project description

Description | Installation | Usage | Contributing


Reusable JupyterHub Pytest Plugin

Latest PyPI version Documentation status GitHub Workflow Status - Test GitHub Test coverage of code

Description

This is a reusable pytest plugin for testing JupyterHub's components

JupyterHub is a modular and extensible project, with components, like the proxy, authenticator and spawner, that can be easily replaced with alternate implementations. Testing the functionality of these components against JupyterHub is important and it requires various hub setups that can sometimes become complicated.

Each of these hub components and the hub itself define their own testing infrastructure, building everything from the ground up using the pytest framework. And some of this complex work is either repetitive across JupyterHub sub-projects, or under-specified for some of them. This has sparked a need to abstract these common parts into a separate testing framework.

The goal is to provide importable testing utilities to make it easier for contributors to write tests for the various hub components. This will involve creating and using fixtures and mocks.

A Fixture is a function that is used to prepare and clean up the environment for a test function. Fixtures can be used to set up test data, test environment, and other resources that are needed by test functions. For more information on Fixtures, check out this pytest documentation on fixtures.

A Mock is an object that simulates the behavior of another object such as a class or function. They are used to simulate the behavior of real objects for testing purposes. For more information on Mocks, check out this unittest documentation on the mock module.

Installation

To use the JupyterHub Pytest Plugin, you will first need to install it using pip:

pip install pytest-jupyterhub

Usage

To use a plugin, first register/load the plugin in your test module or conftest.py file:

pytest_plugins = "jupyterhub-spawners-plugin"

To register multiple plugins:

pytest_plugins = ["jupyterhub-spawners-plugin", "other-plugin"]

For more information, check out this document on Requiring/Loading plugins in a test module or conftest file

All fixtures and mocks inside the plugin will be available to all of your project's test suites. You can use a fixture by passing it as an argument to your test function.

Example

The hub_app fixture is a factory fixture that creates a MockHub instance from a provided config dictionary defining spawner-specific attribute configurations. It then yields the mocked instance. After testing, the running hub instance is stopped and a cleanup is performed.

An illustration of its integration within the DockerSpawner test suite is provided below:

@pytest.fixture
async def app(hub_app):
    config = {
        "Dockerspawner": {
            "prefix": "dockerspawner-test"
        }
    }

    if len(jh_version_info) > 3 and jh_version_info[3]:
        tag = jupyterhub.__version__
        config["Dockerspawner"]["image"] = f"jupyterhub/singleuser:{tag}"

    app = await hub_app(config=config)

    return app

Contributing

If you would like to contribute to the project, please read our contributor documentation and the CONTRIBUTING.md.

The contributor documentation explains how to set up a development installation, how to run the test suite, and how to contribute to documentation.

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_jupyterhub-0.1.0.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

pytest_jupyterhub-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest_jupyterhub-0.1.0.tar.gz.

File metadata

  • Download URL: pytest_jupyterhub-0.1.0.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for pytest_jupyterhub-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fbbff17d873ff5480631cf2299356fb1beef64eda74130f881189deb71cd0696
MD5 2d207b693dce954fa34f7cc6291be641
BLAKE2b-256 67d38831a887c6d939715a67c519be6827e5c84dc10b8492ca0b65e32a694df9

See more details on using hashes here.

Provenance

File details

Details for the file pytest_jupyterhub-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_jupyterhub-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28ee52ad1ffa1489b143976c911693c05886d1a0e2e33409d372a201472e07dc
MD5 fd12bc615aa3056026fe6c3866800050
BLAKE2b-256 0cd73c17cdd4d8f6eac5493e71314a017fddae90674076fe3739883c091af834

See more details on using hashes here.

Provenance

Supported by

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