ipytest
raw JSON → 0.14.2 verified Mon Apr 27 auth: no python
ipytest provides utilities for running unit tests inside IPython notebooks, allowing inline test definition and execution with pytest. Current version: 0.14.2, requires Python >=3.8 and <4. Releases are infrequent.
pip install ipytest Common errors
error ModuleNotFoundError: No module named 'ipytest' ↓
cause ipytest is not installed in the current Python environment.
fix
Run
pip install ipytest and ensure you are using the same kernel as the installation. error UsageError: Cell magic `%%run_tests` not found. ↓
cause The deprecated magic module is not loaded; you may be using a version that removed it.
fix
Use ipytest.run() instead of the cell magic. Or load the magics with
%load_ext ipytest.magics (deprecated). error TypeError: autoconfig() takes 0 positional arguments but 1 was given ↓
cause You are passing arguments to autoconfig() in version 0.14+, which no longer accepts them.
fix
Remove arguments: just call
ipytest.autoconfig() without any parameters. error ValueError: No tests found ↓
cause ipytest.run() could not discover any test functions. Ensure test functions are named with 'test_' prefix and defined before calling run().
fix
Check that your test function names start with 'test_' and that you have defined them before invoking ipytest.run().
Warnings
gotcha ipytest must be imported before any test functions are defined, otherwise tests may not be discovered. ↓
fix Always import ipytest at the top of your notebook cell before defining test functions.
breaking Version 0.14 changed the autoconfig() signature; now it accepts no arguments and configures automatically. Previously, you had to pass a conftest path. ↓
fix Use ipytest.autoconfig() without arguments. Do not pass config paths.
deprecated The ipytest.magics module (e.g., %%run_tests magic) is deprecated in favor of plain Python function calls. ↓
fix Use ipytest.run() instead of the cell magic.
gotcha Tests must be defined inside an IPython notebook cell; ipytest does not work if called from a separate .py file via import. ↓
fix Define tests directly in a notebook cell and execute that cell to register them.
Imports
- ipytest
import ipytest
Quickstart
import ipytest
import pytest
ipytest.autoconfig()
def test_example():
assert 1 + 1 == 2
ipytest.run()