A pytest plugin for testing Jupyter libraries and extensions.
Project description
pytest-jupyter
A set of pytest plugins for Jupyter libraries and extensions.
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.
Note: The server plugin also includes the client plugin, so you can use both
sets of fixtures with "pytest_jupyter.jupyter_server"
. Both the client
and server
plugins also include the core fixtures.
Note: The client and server plugins use pytest-tornasync
for async
test suite running. It may not compatible with pytest-asyncio
, meaning
that all fixtures must be synchronous. You can use the asyncio_loop
fixture
and run asyncio_loop.run_until_complete
against an async function in your
fixtures if needed.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest_jupyter-0.10.1.tar.gz
.
File metadata
- Download URL: pytest_jupyter-0.10.1.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00df54eef9e201dd542d5471b8980def15d34b917b30587d14d7c824fc4d9e84 |
|
MD5 | 13c4f91e9b658dc8621057606f3a3023 |
|
BLAKE2b-256 | 405dcac168223047ddf90d69d2e03958e1eb07b011b5013f5ec8f241eea3ba76 |
File details
Details for the file pytest_jupyter-0.10.1-py3-none-any.whl
.
File metadata
- Download URL: pytest_jupyter-0.10.1-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 644ae23821fe74344e1ff4dfcdbbcd1d6ffc191f654f435f67a19e6dce141684 |
|
MD5 | 4d2386faf858f20d632dcebcf5c75fc1 |
|
BLAKE2b-256 | 87950166c428ea0ab4770f66de7804f2341caa9d8826d0022ce3d986d253d9c6 |