2016-11-21 16 views
0

私は、デフォルトで生成される "自動実行TIMESTAMP"からテストランの名前を変更しようとしています。Testrailsでテストランの名前を変更する方法

私が理想的な状況で望むのは、pytestランナーがテストディレクトリ内のjsonファイルから名前の一部を取得し、これを実行中のテストの相対パスと組み合わせることです。何か違いがあれば、テストは仮想env内にあります。

相対パス(作業領域にある/)test.jsonの

workspace/functional/auth/Test.py 

コンテンツ:

{ "testrail" : "Project Name" } 

コマンドプロンプト実行(ワークスペース/ディレクトリから):

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

Testrailsの期待される名前は 'Project Name - Functional - Auth TIMESTAMP'です

答えて

0

OKこれで、外部ファイルからのインポートをせずにテストの名前を自動的に変更する方法を見つけ出すことができました。 (パスは異なります)

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になる - このワークスペース/ venv /試験/ LIB/python2.7 /サイトパッケージで/ pytest_testrail/plugin.py

変化/auth/Test.pyは 'Functional - Auth Tests TIMESTAMP'という名前で、ワークスペース/機能からのテストは 'Functional - Project Tests TIMESTAMP'という名前になります

関連する問題