跳转到主要内容

pytest插件,提供自动从文件加载数据的功能

项目描述

概述

[Github Actions: Test status]

A pytest插件,提供用于从文件自动加载测试数据的固定装置。

用法

固定装置

此插件为每个测试模块提供以下固定装置。

test_data_info

test_data_info 提供一个 namedtuple 对象,data_from_files.ModuleInfo,具有以下值,针对每个测试模块。

  • root: 测试根目录,默认为 <package_dir>/tests/,可使用 –test-root (test_root) 选项进行配置。

  • datadir: 使用固定装置的测试数据目录将在 <root>/<test_data_dirname>/ 下进行搜索,其中 test_data_dirname 可使用 –test-data-dirname 选项进行配置。

    • 如果使用固定装置的测试代码是 tests/test_foo.py,则 datadir 变为 tests/data/foo/。

    • 如果使用固定装置的测试代码是 tests/foo/bar/test_baz.py,则 datadir 变为 tests/data/foo/bar/baz。

  • subdirs: 如果存在,则相对 datadir 的子目录名称。

test_data

test_data 提供一个 namedtuple 对象的列表或列表的列表,data_from_files.DataInfo,具有以下值。

  • data: 从 <datadir> 下的 <path> 文件加载的数据

  • path: 包含数据的文件路径

  • datadir: 包含测试数据文件的目录

选项

  • –test-root: 测试根目录,其中搜索测试数据 [<package_dir>/tests]

  • –test-data-dirname: 测试数据目录名称 [data]

  • –test-data-pattern: 相对于datadir的测试数据文件路径模式 [**/*.*]

示例

  • tests/test_plugin.py 和 tests/data/plugin/ 目录下的测试数据

  • tests/test_plugin_no_data.py 和 tests/data/plugin_no_data 目录下的测试数据

  • tests/foo/test_bar.py 和 tests/data/foo/bar 目录下的测试数据

安装

要求

  • pytest 显然

  • PyYAML [1] 可选,用于从 YAML 文件加载数据

  • anyconfig [2] 可选,用于加载任何config及其插件支持的格式。

如何安装

  • PyPI

    pip install pytest_data_from_files
  • 从 git 仓库

    pip install git+https://github.com/ssato/pytest-data-from-files
  • 构建 wheel 并安装

    tox -e dists && pip install dist/pytest_data_from_files-*.whl

项目详情


下载文件

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

源分发

pytest-data-from-files-0.2.0.tar.gz (15.8 kB 查看散列)

上传时间

构建分发

pytest_data_from_files-0.2.0-py2.py3-none-any.whl (8.9 kB 查看散列)

上传时间 Python 2 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面