Metadata-Version: 2.4
Name: pytest-testbook
Version: 1.5.0
Summary: Enables pytest to execute your Jupyter Notebook as a test
Author: Ernesto D. Luzon Jr.
Project-URL: Homepage, https://github.com/ldiary/pytest-testbook
Project-URL: Repository, https://github.com/ldiary/pytest-testbook
Project-URL: Bug Tracker, https://github.com/ldiary/pytest-testbook/issues
Classifier: Framework :: Pytest
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: <3.15,>=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pytest>=5.4.0
Requires-Dist: nbformat
Requires-Dist: jupyter_client
Requires-Dist: playwright
Dynamic: license-file

pytest-testbook
===================================

[![Build Status](https://github.com/ldiary/pytest-testbook/actions/workflows/tests.yml/badge.svg)](https://github.com/ldiary/pytest-testbook/actions/workflows/tests.yml) 
[![See Build Status on AppVeyor](https://ci.appveyor.com/api/projects/status/github/ldiary/pytest-testbook?branch=master)](https://ci.appveyor.com/project/ldiary/pytest-testbook/branch/master)

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"`

```python
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:
```python
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

