跳转到主要内容

解析测试结果以告知需求

项目描述

testreqstatus

PyPI - Version PyPI - Python Version


pip install testreqstatus

用法

  1. 为测试名称建立一组对应的需求

    {
      "DMS356": [
        "romancal.regtest.test_mos_pipeline.test_level3_mos_pipeline"
      ],
      "DMS373": [
        "romancal.regtest.test_mos_pipeline.test_hlp_mosaic_pipeline"
      ],
      "DMS374": [
        "romancal.regtest.test_mos_pipeline.test_level3_mos_pipeline"
      ],
      "DMS400": [
        "romancal.regtest.test_mos_pipeline.test_level3_mos_pipeline"
      ]
    }
    

[!TIP]要从带有@metrics_logger装饰器的现有测试中提取测试需求,请使用RequirementTests.from_test_directory()

from testreqstatus import RequirementTests

requirements = RequirementTests.from_test_directory("~/projects/romancal/")
requirements.to_file("test_requirements.json")
  1. 运行测试并生成JUnitXML结果文件

    <?xml version="1.0" encoding="utf-8"?>
    <testsuites>
      <testsuite name="pytest" errors="0" failures="0" skipped="0" tests="2" time="2021.550" timestamp="2024-08-23T00:23:01.454354" hostname="spacetelescope-runner-2ls89-rrbf2">
        <testcase classname="romancal.regtest.test_mos_pipeline" name="test_level3_mos_pipeline" time="677.728">
        </testcase>
        <testcase classname="romancal.regtest.test_mos_pipeline" name="test_hlp_mosaic_pipeline" time="486.642">
        </testcase>
      </testsuite>
    </testsuites>
    
  2. 使用RequirementTestResults.requirements_by_test_result检索每个测试及其对应需求的状态

    from testreqstatus import RequirementTestResults
    
    results = RequirementTestResults(
        test_requirements="examples/test_requirements.json",
        test_results="examples/results.xml",
    )
    
    print(results.requirements_by_test_result)
    
    {
      "romancal.regtest.test_mos_pipeline.test_level3_mos_pipeline": {
        "status": "PASS",
        "requirements": [
          "DMS356",
          "DMS374",
          "DMS400"
        ]
      },
      "romancal.regtest.test_mos_pipeline.test_hlp_mosaic_pipeline": {
        "status": "PASS",
        "requirements": [
          "DMS373"
        ]
      }
    }
    

[!TIP]您还可以使用RequirementTestResults.test_results_by_requirement获取反向映射(需求和它们的对应测试状态)

print(results.test_results_by_requirement)
{
  "DMS356": {
    "romancal.regtest.test_mos_pipeline.test_level3_mos_pipeline": "PASS"
  },
  "DMS373": {
    "romancal.regtest.test_mos_pipeline.test_hlp_mosaic_pipeline": "PASS"
  },
  "DMS374": {
    "romancal.regtest.test_mos_pipeline.test_level3_mos_pipeline": "PASS"
  },
  "DMS400": {
    "romancal.regtest.test_mos_pipeline.test_level3_mos_pipeline": "PASS"
  }
}

项目详情


下载文件

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

源代码分发

testreqstatus-0.6.0.tar.gz (290.0 kB 查看哈希值)

上传时间: 源代码

构建分发

testreqstatus-0.6.0-py3-none-any.whl (29.1 kB 查看哈希值)

上传于 Python 3

由以下组织支持