用于测试Jupyter库和扩展的pytest插件。
pytest-jupyter的Python项目详细描述
皮斯特·朱皮特
一组用于Jupyter库和扩展的pytest插件。在
基本用法
首先,使用pip从PyPI安装pytest-jupyter
:
pip install pytest-jupyter
这将安装基本的pytest jupyter包,其中包括各种基于jupyter的pytest插件的fixture定义。在
要使用这些插件之一,还需要安装它们的依赖项。这需要第二个pip install
调用。例如,如果您想使用jupyter_server
插件,您需要调用:
这个应该安装插件工作所需的一切。在
要使用插件,请将其添加到项目根测试目录的pytest_plugins
列表中。在
# inside the conftest.pypytest_plugins=["pytest_jupyter.jupyter_server"]
插件中的所有fixture(例如jupyter_服务器)将可用于项目的所有单元测试。通过将fixture作为参数传递给单元测试函数,可以使用fixture:
asyncdeftest_jupyter_server_api(jp_fetch):# Send request to a temporary Jupyter Server Web Applicationresponse=awaitjp_fetch("api/spec.yml")# Confirm that the request is successful.assertresponse.code==200
可以使用pytest命令行界面中的--fixtures
参数列出给定插件的fixture:
pytest --fixtures -p pytest_jupyter.jupyter_server
或者调用pytest --fixtures
,其中插件列在给定测试目录的pytest_plugins
变量中。在
- 项目
标签: