- Notifications
You must be signed in to change notification settings - Fork38
🧪 📗 Unit test your Jupyter Notebooks the right way
License
nteract/testbook
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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 upconventional 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 Notebookexample_notebook.ipynb:
deffunc(a,b):returna+b
You would write a unit test usingtestbook in a Python fileexample_test.py as follows:
# example_test.pyfromtestbookimporttestbook@testbook('/path/to/example_notebook.ipynb',execute=True)deftest_func(tb):func=tb.get("func")assertfunc(1,2)==3
Thenpytest can be used to run the test:
pytest example_test.pypip install testbookNOTE: 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 withpip 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]Seereadthedocs for more in-depth details.
ReadCONTRIBUTING.md for guidelines on how to setup a local development environment and make code changes back to testbook.
About
🧪 📗 Unit test your Jupyter Notebooks the right way
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.