【问题标题】:How to rename test runs in Testrail automatically如何在 Testrail 中自动重命名测试运行
【发布时间】:2016-11-21 22:35:02
【问题描述】:

我正在尝试从默认生成的“Automated Run TIMESTAMP”自动重命名测试运行。

在理想情况下,我希望 pytest 运行程序从测试目录中的 json 文件中获取部分名称,并将其与我正在运行的测试的相对路径结合起来。如果这有什么不同的话,测试就在一个虚拟环境中。

相对路径:

workspace/functional/auth/Test.py

test.json 的内容(在 workspace/ 中):

{ "testrail" : "Project Name" }

命令提示符执行(从工作区/目录):

$ py.test --testrail=testrail.cfg functional/auth/Test.py

Testrails 中的预期名称是“项目名称 - 功能 - Auth TIMESTAMP”

【问题讨论】:

    标签: python command-line pytest testrail


    【解决方案1】:

    好的,所以我能够找到一种无需从外部文件导入即可自动重命名测试的方法。

    在 workspace/venv/test/lib/python2.7/site-packages/pytest_testrail/plugin.py 中更改它 - (路径会有所不同)

    import os
    
    def testrun_name(location):
    """
    Returns testrun name with timestamp
    Edited to grab the directory and name the test based off of that
    """
    projects = {mapping of projects}
    suite = {mapping of sub folders to function names}
    
    absolute_path = os.getcwd()
    project_dir = absolute_path.split('workspace/')[1]
    
    now = datetime.utcnow()
    return '{} - {} Tests {}'.format(projects[project_dir],suite[location],now.strftime(DT_FORMAT))
    
    @pytest.hookimpl(trylast=True)
    def pytest_collection_modifyitems(self, session, config, items):
    
        # Create list of locations of the test cases
        locations = []
        location = 'project'
        for item in items:
            loc = item.location[0].split('/')[1]
            if loc not in locations:
                locations.append(loc)
        # Remove the Testrails location
        if '..' in locations:
            locations.remove('..')
        # Check length of list to determine if running individual test
        if len(locations) == 1:
            location = locations[0]
    
        tr_keys = get_testrail_keys(items)
        self.create_test_run(
            self.assign_user_id,
            self.project_id,
            self.suite_id,
            testrun_name(location),
            tr_keys
        )
    

    这会导致工作区/功能/身份验证/Test.py 中的测试运行被命名为“功能 - 身份验证测试 TIMESTAMP”,工作区/功能中的测试被命名为“功能 - 项目测试 TIMESTAMP”

    【讨论】:

      猜你喜欢
      • 2020-02-21
      • 2018-12-20
      • 1970-01-01
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-03
      • 1970-01-01
      相关资源
      最近更新 更多