跳转到主要内容

用于使用YAML文件配置工作流程/管道测试的pytest插件

项目描述

More information on how to cite pytest-workflow here.

pytest-workflow是一个与工作流程系统无关的测试框架,旨在通过使用YAML文件进行测试配置,使管道/工作流程测试变得简单。无论您使用WDL、snakemake、nextflow、bash还是任何其他工作流程框架编写管道,pytest-workflow都可以使测试变得简单。pytest-workflow是建立在pytest测试框架之上的。

要查看完整文档和示例,请访问我们的 readthedocs 页面

安装

Pytest-workflow 需要 Python 3.7 或更高版本。它在 Python 3.7、3.8、3.9、3.10 和 3.11 上进行了测试。

  • 请确保您的虚拟环境已激活。

  • 使用 pip 安装 pip install pytest-workflow

  • 在您的仓库根目录下创建一个 tests 目录。

  • tests 目录中创建您的测试 yaml 文件。

Pytest-workflow 还可以在 conda-forge 上作为 conda 包 使用。按照 这些说明 正确设置通道,以便使用 conda-forge。或者,您可以为使用 bioconda 正确设置通道 设置通道。之后,可以使用 conda install pytest-workflow 来安装 pytest-workflow。

快速入门

在安装了 pytest-workflow 的环境中运行 pytest。Pytest 将自动收集 tests 目录中以 test 开头并以 .yaml.yml 结尾的文件。

要检查运行中的工作流的进度,您可以使用 tail -f 在工作流的 stdoutstderr 文件上。一旦启动工作流,这些文件的路径就会在日志中报告。

建议使用 --kwd--keep-workflow-wd 标志进行管道调试。这将保留工作流目录和日志,以便在测试运行后进行检查,以便可以检查管道崩溃的位置。同时,-v 标志也很有用,因为它提供了成功和失败测试的完整概述。

下面是一个定义测试的 YAML 文件示例

- name: Touch a file
  command: touch test.file
  files:
    - path: test.file

这将运行 touch test.file 并检查之后是否存在路径为 test.file 的文件。它还会检查命令是否以退出代码 0 退出,这是唯一默认运行的测试。也可以测试以其他退出代码退出的工作流。还可以进行其他预定义测试以及自定义测试。

- name: moo file                     # The name of the workflow (required)
  command: bash moo_workflow.sh      # The command to execute the workflow (required)
  files:                             # A list of files to check (optional)
    - path: "moo.txt"                # File path. (Required for each file)
      contains:                      # A list of strings that should be in the file (optional)
        - "moo"
      must_not_contain:              # A list of strings that should NOT be in the file (optional)
        - "Cock a doodle doo"
      md5sum: e583af1f8b00b53cda87ae9ead880224   # Md5sum of the file (optional)
      encoding: UTF-8                # Encoding for the text file (optional). Defaults to system locale.

- name: simple echo                  # A second workflow. Notice the starting `-` which means
  command: "echo moo"                # that workflow items are in a list. You can add as much workflows as you want
  files:
    - path: "moo.txt"
      should_exist: false            # Whether a file should be there or not. (optional, if not given defaults to true)
  stdout:                            # Options for testing stdout (optional)
    contains:                        # List of strings which should be in stdout (optional)
      - "moo"
    must_not_contain:                # List of strings that should NOT be in stout (optional)
      - "Cock a doodle doo"
    encoding: ASCII                  # Encoding for stdout (optional). Defaults to system locale.

- name: mission impossible           # Also failing workflows can be tested
  tags:                              # A list of tags that can be used to select which test
    - should fail                    # is run with pytest using the `--tag` flag.
  command: bash impossible.sh
  exit_code: 2                       # What the exit code should be (optional, if not given defaults to 0)
  files:
    - path: "fail.log"               # Multiple files can be tested for each workflow
    - path: "TomCruise.txt.gz"       # Gzipped files can also be searched, provided their extension is '.gz'
      contains:
        - "starring"
      extract_md5sum: e27c52f6b5f8152aa3ef58be7bdacc4d   # Md5sum of the uncompressed file (optional)
  stderr:                            # Options for testing stderr (optional)
    contains:                        # A list of strings which should be in stderr (optional)
      - "BSOD error, please contact the IT crowd"
    must_not_contain:                # A list of strings which should NOT be in stderr (optional)
      - "Mission accomplished!"
    encoding: UTF-16                 # Encoding for stderr (optional). Defaults to system locale.

- name: regex tests
  command: echo Hello, world
  stdout:
    contains_regex:                  # A list of regex patterns that should be in stdout (optional)
      - 'Hello.*'                    # Note the single quotes, these are required for complex regexes
      - 'Hello .*'                   # This will fail, since there is a comma after Hello, not a space

    must_not_contain_regex:          # A list of regex patterns that should not be in stdout (optional)
      - '^He.*'                      # This will fail, since the regex matches Hello, world
      - '^Hello .*'                  # Complex regexes will break yaml if double quotes are used

有关 Python 如何解析正则表达式的更多信息,请参阅 Python 文档

有关包括自定义测试在内的更高级用例的文档,请访问我们的 readthedocs 页面

项目详情


下载文件

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

源分布

pytest-workflow-2.1.0.tar.gz (50.3 kB 查看哈希值)

上传时间

构建分布

pytest_workflow-2.1.0-py3-none-any.whl (40.1 kB 查看散列值)

上传时间 Python 3

由以下支持