{"id":22453,"library":"testbook","title":"testbook","description":"A unit testing framework for Jupyter Notebooks. Current version 0.4.2 (release cadence: infrequent, last release Sep 2021). Allows writing and running tests for notebook cells using Python test frameworks.","status":"active","version":"0.4.2","language":"python","source_language":"en","source_url":"https://github.com/nteract/testbook","tags":["jupyter","testing","notebook","unit-testing"],"install":[{"cmd":"pip install testbook","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Importing the module directly gives you the package, not the decorator/context manager. The main API is the testbook function/decorator.","wrong":"import testbook","symbol":"testbook","correct":"from testbook import testbook"}],"quickstart":{"code":"from testbook import testbook\n\n@testbook('notebook.ipynb', execute=True)\ndef test_something(tb):\n    result = tb.cell_output(0)\n    assert result == 42\n","lang":"python","description":"Decorate a test function with @testbook, specifying the notebook path. The test function receives a Testbook object. Calling tb.cell_output(index) retrieves the output of a cell."},"warnings":[{"fix":"Set execute=False in the decorator: @testbook('notebook.ipynb', execute=False), then run tb.execute_cell(0) to run specific cells in your test.","message":"When using execute=True (default), the entire notebook is executed before test. This may be slow and side-effect heavy. Use execute=False for partial execution.","severity":"gotcha","affected_versions":"all"},{"fix":"Use tb.cell_output_slice() or iterate with tb.cells to find the correct index. Alternatively, use cell tags in the notebook to reference cells by name.","message":"Cell indices are 0-based, but non-code cells (e.g. markdown) are skipped. Counting cells manually can be error-prone.","severity":"gotcha","affected_versions":"all"},{"fix":"Update imports: from testbook import testbook. Use @testbook decorator or context manager.","message":"The old API function 'testbook.testbook' (lowercase) has been deprecated in favor of the decorator usage.","severity":"deprecated","affected_versions":"<0.4.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install testbook: pip install testbook","cause":"testbook is not installed or installed in a different environment.","error":"ModuleNotFoundError: No module named 'testbook'"},{"fix":"Use: from testbook import testbook","cause":"Old import style (import testbook then testbook.testbook) no longer works in recent versions.","error":"AttributeError: module 'testbook' has no attribute 'testbook'"},{"fix":"Use an absolute path or set the working directory to the notebook's location.","cause":"The notebook path is relative and may not be correct when running tests from a different directory.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'notebook.ipynb'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}