Skip to main content

jupyter_kernel_test

jupyter_kernel_test is a tool for testing Jupyter kernels. It tests kernels for successful code execution and conformance with the Jupyter Messaging Protocol (currently 5.0).

Install

Install it with pip (python3.4 or greater required):

pip3 install jupyter_kernel_test

Usage

To use it, you need to write a (python) unittest file containing code samples in the relevant language which test various parts of the messaging protocol. A short example is given below, and you can also refer to the test_ipykernel.py and test_irkernel.py files for complete examples.

Some parts of the messaging protocol are relevant only to the browser-based notebook (rich display) or console interfaces (code completeness, history searching). Only parts of the spec for which you provide code samples are tested.

Run this file directly using python, or use nosetests or py.test to find and run it.

Example

import unittest
import jupyter_kernel_test


class MyKernelTests(jupyter_kernel_test.KernelTests):
    # Required --------------------------------------

    # The name identifying an installed kernel to run the tests against
    kernel_name = "mykernel"

    # language_info.name in a kernel_info_reply should match this
    language_name = "mylanguage"

    # Optional --------------------------------------

    # Code in the kernel's language to write "hello, world" to stdout
    code_hello_world = "print 'hello, world'"

    # Pager: code that should display something (anything) in the pager
    code_page_something = "help(something)"

    # Samples of code which generate a result value (ie, some text
    # displayed as Out[n])
    code_execute_result = [{"code": "6*7", "result": "42"}]

    # Samples of code which should generate a rich display output, and
    # the expected MIME type
    code_display_data = [{"code": "show_image()", "mime": "image/png"}]

    # You can also write extra tests. We recommend putting your kernel name
    # in the method name, to avoid clashing with any tests that
    # jupyter_kernel_test adds in the future.
    def test_mykernel_stderr(self):
        self.flush_channels()
        reply, output_msgs = self.execute_helper(code='print_err "oops"')
        self.assertEqual(output_msgs[0]["header"]["msg_type"], "stream")
        self.assertEqual(output_msgs[0]["content"]["name"], "stderr")
        self.assertEqual(output_msgs[0]["content"]["text"], "oops\n")


if __name__ == "__main__":
    unittest.main()

Coverage

The following aspects of the messaging protocol are not explicitly tested:

  • Widget comms: comm_open, comm_msg, comm_close

  • stdin: input_request, input_reply

  • display_data metadata

  • Shutdown/restart: shutdown_request, shutdown_reply

  • History: not all option combinations covered

  • Inspection: multiple levels

  • Execution payloads (deprecated but still used): payloads load, edit, ask_exit

  • User expressions

  • Execution: combinations of silent, store_history and stop_on_error

Metadata

Release files for jupyter-kernel-test 0.7.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 jupyter-kernel-test 0.7.0
File Size Uploaded
jupyter_kernel_test-0.7.0.tar.gz 17.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jupyter-kernel-test 0.7.0
File Interpreter ABI Platform
jupyter_kernel_test-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.6 kB

Release files / jupyter_kernel_test-0.7.0.tar.gz

Download URL jupyter_kernel_test-0.7.0.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
078b6fe7f770dd164f9549bdd7a355663225a3ff9b0f7575ad546d27239ec609
BLAKE2b-256 checksum
How to use checksums
b08600e0f5a663b10f40754ed7f3a9debb0ef3bc3f724cc32356b7b6bb4ca157
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.11.8

Release files / jupyter_kernel_test-0.7.0-py3-none-any.whl

Download URL jupyter_kernel_test-0.7.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c60503b36cf0c58a7fb3b62e29254d2f2a9bd11c3fe634041e46f0a9b9eab98
BLAKE2b-256 checksum
How to use checksums
7242d57a938cad4e99bb799f35105561959b0a0550c65fbc1ed671196e27f909
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

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