Skip to main content

pytest-testbook

Build Status See Build Status on AppVeyor

The Question:

What do you call a Jupyter Notebook filled with test cases?

The Answer:

a testbook !

Why invent this plugin?

Because it allows specification, test cases, and automation code to be recorded inside a single Jupyter Notebook. When specification, requirements, test cases, and automation code are written in one place, this place is called a testbook.

How to run the tests?

  • Option 1: Follow the manual steps written in the testbook and perform each test steps manually.
  • Option 2: Trigger the execution of automated test code by running each cell directly in Jupyter Notebook.
  • Option 3: Use pytest to discover tests inside the testbook and run them. This your option when running testbook in CI/CD pipeline.

Features

  • BDD-style specification, requirements, manual test steps, and test automation code.
  • Auto-generated PDF reports to support auditing processes.
  • Plugin managed playwright instance working on its own background thread but can be used inside Jupyter Notebook cells.
  • Trigger automated tests execution in Jupyter.
  • Upload testbook in CI/CD pipepline for auto-execution using pytest

Getting Started

You will need to install playwright to generate pdf test reports. The side-effect is that you get a free playwright instance that you can use in your Testbooks.

pip install pytest-testbook
pip install jupyterlab
playwright install chromium

Usage

Navigate to where your tests folder are located. Then either run:

jupyter lab

to run tests manually in Jupyter. Or you can run:

pytest -sv

instead to let pytest discover your tests, collect them and execute them.

Advanced Usage

The default behaviour of the plugin is to look for Testbook cells that starts with any of these: "### Given", "### And", "### When", "### Then", "### But"

def pytest_addoption(parser):
    # Register a new INI option that accepts a list of strings
    parser.addini(
        name="testbook_step_prefixes",
        help="List of markdown prefixes that indicate a test step in the notebook",
        type="linelist",
        default=["### Given", "### And", "### When", "### Then", "### But"]
    )

You can override this behaviour and change it to your projects needs in you conftest.py, for example:

def pytest_configure(config):
    # Safely attach a custom attribute to the config object
    config.custom_testbook_prefixes = [
        "### TC-SYS-INT-"
    ]

License

Distributed under the terms of the MIT_ license, "pytest-testbook" is free and open source software

Release files for pytest-testbook 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-testbook 1.5.0
File Size Uploaded
pytest_testbook-1.5.0.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-testbook 1.5.0
File Interpreter ABI Platform
pytest_testbook-1.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.9 kB

Release files / pytest_testbook-1.5.0.tar.gz

Download URL pytest_testbook-1.5.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7082332f832cfcd41f41bbb1e6a876050828abd82c456085c651c6f1989b5354
BLAKE2b-256 checksum
How to use checksums
d9c6371a83fe27c5b913a07c68864791c369f0d9c661be0670af2e1a95b3c771
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / pytest_testbook-1.5.0-py3-none-any.whl

Download URL pytest_testbook-1.5.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f5701af04e124e6f096a0df6ff59a71f1bd5569e380edac4b288bf75f814306
BLAKE2b-256 checksum
How to use checksums
061dfd8902d7b643e6b6c3adebe2445ea7e7ce71d8a72cb3e8ae86f6406a45ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

1.5.0 This release

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.3.5

2 release files

1.2.6

2 release files

1.2.5

2 release files

0.0.25

2 release files

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page