2016-11-21 36 views
0

我試圖從默認生成的「自動運行TIMESTAMP」中自動重命名測試運行。如何在Testrails中重命名測試運行

我想在理想的情況下,pytest跑步者從測試目錄中的json文件中獲取部分名稱,並將其與我正在運行的測試的相對路徑相結合。這些測試在虛擬env中,如果有任何區別的話。

相對路徑:

workspace/functional/auth/Test.py 

內容test.json的(這是在工作區/):

{ "testrail" : "Project Name" } 

命令提示執行(從工作區/ DIR):

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

Testrails中的預期名稱是'項目名稱 - 功能 - 驗證TIMESTAMP'

回答

0

好吧,我能夠想出一種方法來自動重命名測試,而無需從外部文件導入。

變化這在工作區的/ VENV /測試/ LIB/python2.7 /站點包/ 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 
    ) 

這導致從工作區/功能一testrun /auth/Test.py命名爲'Functional-Auth Tests TIMESTAMP',並從工作區/功能測試中命名爲'Functional-Project Tests TIMESTAMP'

相關問題