好的,所以我能够找到一种自动重命名测试的方法,而无需从外部文件导入。
在 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”