跳转到主要内容

pytest插件,用于测试Jupyter库和扩展。

项目描述

pytest-jupyter

一组pytest插件,用于Jupyter库和扩展。

Build Status

基本用法

首先,使用pip从PyPI安装pytest-jupyter

pip install pytest-jupyter

这会安装基本的pytest-jupyter包,其中包含各种基于Jupyter的pytest插件的固定定义。

要使用这些插件之一,您还需要安装它们的依赖项。这需要第二次pip install调用。例如,如果您想使用jupyter_server插件,您需要调用

pip install "pytest-jupyter[server]"

这应该会安装插件工作所需的所有内容。

要使用插件,请将其添加到项目根测试目录中的conftest.py文件的pytest_plugins列表中。

# inside the conftest.py

pytest_plugins = ["pytest_jupyter.jupyter_server"]

此库包括一个echo_kernel,这有助于加速测试。您必须安装"pytest-jupyter[server]""pytest-jupyter[client]"才能使用echo内核。

pytest_jupyter.jupyter_client插件提供一个安装的echo_kernel_spec作为固定装置,以及一个start_kernel固定装置,该装置提供了一个工厂函数,默认使用echo内核启动内核。

注意:服务器插件还包含客户端插件,因此您可以使用"pytest_jupyter.jupyter_server"使用这两组固定装置。客户端和服务器插件还包含核心固定装置。

注意:客户端和服务器插件使用pytest-tornasync进行异步测试套件运行。它可能与pytest-asyncio不兼容,这意味着所有固定装置都必须是同步的。如果需要,您可以使用asyncio_loop固定装置并在您的固定装置中对异步函数调用asyncio_loop.run_until_complete

服务器固定装置默认使用echo内核。要覆盖此行为,覆盖jp_server_config固定装置并添加以下配置

{
    "MultiKernelManager": {
        "default_kernel_name": "<desired_kernel_name"
    }
}

插件内部的所有固定装置(例如jupyter_server)都将对项目的所有单元测试可用。您可以通过将固定装置作为参数传递给单元测试函数来使用固定装置。

async def test_jupyter_server_api(jp_fetch):
    # Send request to a temporary Jupyter Server Web Application
    response = await jp_fetch("api/spec.yml")

    # Confirm that the request is successful.
    assert response.code == 200

您可以使用pytest命令行界面中的--fixtures参数列出特定插件的固定装置

pytest --fixtures -p pytest_jupyter.jupyter_server

或通过调用pytest --fixtures,其中插件在给定测试目录的pytest_plugins变量中列出。

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

pytest_jupyter-0.10.1.tar.gz (15.6 kB 查看散列)

上传时间

构建分布

pytest_jupyter-0.10.1-py3-none-any.whl (17.7 kB 查看散列)

上传时间 Python 3

由以下提供支持