Skip to content
プロジェクト

概要

🧪 📗 Jupyter Notebookを適切な方法でユニットテストできます。

開発ツール

この数値の測り方

計測したスター増加

24時間
0
7日間
-1
15日間
-1
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

Build Status image Documentation Status image image image Code style: black

testbook

testbook is a unit testing framework extension for testing code in Jupyter Notebooks.

Previous attempts at unit testing notebooks involved writing the tests in the notebook itself. However, testbook will allow for unit tests to be run against notebooks in separate test files, hence treating .ipynb files as .py files.

testbook helps you set up conventional unit tests for your Jupyter Notebooks.

Here is an example of a unit test written using testbook

Consider the following code cell in a Jupyter Notebook example_notebook.ipynb:

def func(a, b):
   return a + b

You would write a unit test using testbook in a Python file example_test.py as follows:

# example_test.py
from testbook import testbook


@testbook('/path/to/example_notebook.ipynb', execute=True)
def test_func(tb):
   func = tb.get("func")

   assert func(1, 2) == 3

Then pytest can be used to run the test:

pytest example_test.py

Installing testbook

pip install testbook

NOTE: This does not install any kernels for running your notebooks. You'll need to install in the same way you do for running the notebooks normally. Usually this is done with pip install ipykernel

Alternatively if you want all the same dev dependencies and the ipython kernel you can install these dependencies with:

pip install testbook[dev]

Documentation

See readthedocs for more in-depth details.

Development Guide

Read CONTRIBUTING.md for guidelines on how to setup a local development environment and make code changes back to testbook.

関連プロジェクトを探す

読み込み中…