跳转到主要内容

pytest收集输出的格式化器

项目描述

pytest-collect-formatter

pytest插件,用于格式化收集的测试输出。

  • 免费软件:MIT许可证

要求

  • pyyaml

  • dicttoxml

安装

您可以通过pip安装“pytest-collect-formatter”

$ pip install pytest-collect-formatter

用法

  • 通过正常运行pytest使用此插件,并使用以下选项自定义收集格式,最好与–collect-only选项一起使用

>>> collect-formatter:
  --collect-output-file=COLLECT_OUTPUT_FILE
                        Saves collected test items to the file
  --collect-format=COLLECT_FORMAT
                        Saves collected test items specified format [xml, yaml, json]
  --collect-type=COLLECT_TYPE
                        Format output results in classic pytest view or in 'path' view [classic, path], default classic

用法示例

$ pytest tests –collect-output-file my_tests_structure.xml –collect-format xml

您将得到my_tests_structure.xml

格式示例

PATH

JSON

[
    {
        "type": "path",
        "title": "examples",
        "children": [
            {
                "type": "path",
                "title": "tests",
                "children": [
                    {
                        "type": "path",
                        "title": "test_formatter",
                        "children": [
                            {
                                "type": "path",
                                "title": "test_fromatter_v1.py",
                                "children": [
                                    {
                                        "type": "pytest_unit",
                                        "title": "TestFormatter",
                                        "children": [
                                            {
                                                "type": "pytest_unit",
                                                "title": "test_inside_class",
                                                "children": []
                                            },
                                            {
...

YAML

 - children:
   - children:
     - children:
       - children:
         - children:
           - children: []
             title: test_inside_class
             type: pytest_unit
           - children: []
             title: test_inside_class_parametrize[1]
             type: pytest_unit
           - children: []
             title: test_inside_class_parametrize[2]
             type: pytest_unit
           - children: []
             title: test_inside_class_parametrize[3]
...

XML

<?xml version="1.0" ?>
<root>
    <item>
        <type>path</type>
        <title>examples</title>
        <children>
            <item>
                <type>path</type>
                <title>tests</title>
                <children>
                    <item>
                        <type>path</type>
                        <title>test_formatter</title>
                        <children>
                            <item>
                                <type>path</type>
                                <title>test_fromatter_v1.py</title>
                                <children>
                                    <item>
                                        <type>pytest_unit</type>
                                        <title>TestFormatter</title>
                                        <children>
                                            <item>
                                                <type>pytest_unit</type>
                                                <title>test_inside_class</title>
                                                <children/>
                                            </item>
...

CLASSIC

JSON

[
 {
     "type": "Package",
     "value": "test_formatter",
     "children": [
         {
             "type": "Module",
             "value": "test_fromatter_v1.py",
             "children": [
                 {
                     "type": "Class",
                     "value": "TestFormatter",
                     "children": [
                         {
                             "type": "Function",
                             "value": "test_inside_class"
                         }
 ....

YAML

- children:
  - children:
    - children:
      - type: Function
        value: test_inside_class
      - type: Function
        value: test_inside_class_parametrize[1]
      - type: Function
        value: test_inside_class_parametrize[2]
      - type: Function
        value: test_inside_class_parametrize[3]
      - type: Function
        value: test_inside_class_parametrize[4]
      type: Class
      value: TestFormatter
    - type: Function
      value: test_outside_of_class
    type: Module
    value: test_fromatter_v1.py
  type: Package
  value: test_formatter
....

XML

<?xml version="1.0" ?>
<root>
    <item>
        <type>Package</type>
        <value>test_formatter</value>
        <children>
            <item>
                <type>Module</type>
                <value>test_fromatter_v1.py</value>
                <children>
                    <item>
                        <type>Class</type>
                        <value>TestFormatter</value>
                        <children>
                            <item>
                                <type>Function</type>
                                <value>test_inside_class</value>
                            </item>
                            <item>
                                <type>Function</type>
                                <value>test_inside_class_parametrize[1]</value>
                            </item>
                            <item>
                                <type>Function</type>
                                <value>test_inside_class_parametrize[2]</value>
                            </item>
                            <item>
                                <type>Function</type>
                                <value>test_inside_class_parametrize[3]</value>
                            </item>
                            <item>
                                <type>Function</type>
                                <value>test_inside_class_parametrize[4]</value>
                            </item>
                        </children>
                    </item>
                    <item>
                        <type>Function</type>
                        <value>test_outside_of_class</value>
                    </item>
                </children>
            </item>
        </children>
....

更多示例可以在examples文件夹以及测试结构中找到

问题

如果您遇到任何问题,请附上详细描述后提交问题

致谢

致谢

开发主管

贡献者

项目详情


下载文件

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

源分发

pytest-collect-formatter-0.4.0.tar.gz (6.8 kB 查看哈希值)

上传时间

构建分发

pytest_collect_formatter-0.4.0-py2.py3-none-any.whl (5.8 kB 查看哈希值)

上传时间 Python 2 Python 3

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