diff --git a/executor.json b/executor.json deleted file mode 100644 index f0edd9e..0000000 --- a/executor.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "Jenkins", - "type": "jenkins", - "url": "http://example.org", - "buildOrder": 13, - "buildName": "allure-report_deploy#13", - "buildUrl": "http://example.org/build#13", - "reportUrl": "http://example.org/build#13/AllureReport", - "reportName": "Demo allure report" -} \ No newline at end of file diff --git a/main-runtest.py b/main-runtest.py new file mode 100644 index 0000000..d1a82b3 --- /dev/null +++ b/main-runtest.py @@ -0,0 +1,88 @@ +from os import system as exec_system_command +from os.path import exists as is_file_exists +from os import environ +from os.path import dirname +from sys import argv as term_args +from sys import executable +import platform +import json + +# Must run as the main program. +if __name__ != '__main__': + raise SystemExit('The current file can only be run as the main program, and it is forbidden to be imported.') + + +# Main command line. +first_command_status = exec_system_command(""" +pytest --alluredir ./allure-results --clean-alluredir %s +""" % "\x20".join(term_args[1:])) + + +allure_results = '%s/allure-results' % dirname(__file__) + +if is_file_exists(allure_results): + allure_results_categories = '%s/categories.json' % allure_results + open(allure_results_categories, mode='w', encoding='utf-8').write(json.dumps([ + { + "name": "通过", + "matchedStatuses": [ + "passed" + ] + }, + { + "name": "失败", + "matchedStatuses": [ + "failed" + ] + }, + { + "name": "测试发生错误", + "matchedStatuses": [ + "broken" + ] + }, + { + "name": "加载超时异常", + "matchedStatuses": [ + "broken" + ], + "messageRegex": ".*TimeoutException.*" + } + ], indent=4, ensure_ascii=False)) +if is_file_exists(allure_results): + allure_results_environment_properties = '%s/environment.properties' % allure_results + open(allure_results_environment_properties, mode='w').write("OS = %s\nPython = %s\nExecute = %s" % ( + ('%s (%s %s) %s' % (platform.node(), platform.system(), platform.release(), platform.machine().lower())), + ('%s' % (platform.python_version())), + executable.replace("\\", '/') + )) +if is_file_exists(allure_results): + executor_file = '%s/executor.json' % allure_results + if True: + c = 0 + if 'PYCHARM_HOSTED' in environ.keys(): + c = 1 + if 'CI' in environ.keys() or 'JENKINS_HOME' in environ.keys(): + c = 2 + match c: + case 0: + open(executor_file, mode='w').write(json.dumps( + { + 'name': 'Python', + 'type': 'python', + 'buildName': ' ' + }, + indent=4, ensure_ascii=False + )) + case 1: + open(executor_file, mode='w').write(json.dumps( + { + 'name': 'PyCharm', + 'type': 'pycharm', + 'buildName': ' ' + }, + indent=4, ensure_ascii=False + )) + +# Return to the main command line status code. +exit(first_command_status) diff --git a/runtest.py b/runtest.py deleted file mode 100644 index 14ce86e..0000000 --- a/runtest.py +++ /dev/null @@ -1,60 +0,0 @@ -from os import system as exec_system_command -from os.path import exists as is_file_exists -from os.path import dirname -from sys import argv as term_args -from sys import executable -import platform - - -if __name__ != '__main__': - raise SystemExit('The current file can only be run as the main program, and it is forbidden to be imported.') - -first_command_status = exec_system_command(""" -pytest --alluredir ./allure-results --clean-alluredir %s -""" % "\x20".join(term_args[1:])) - -allure_results = '%s/allure-results' % dirname(__file__) -allure_results_categories = '%s/categories.json' % allure_results -allure_results_categories_content = """ -[ - { - "name": "通过", - "matchedStatuses": [ - "passed" - ] - }, - { - "name": "失败", - "matchedStatuses": [ - "failed" - ] - }, - { - "name": "测试发生错误", - "matchedStatuses": [ - "broken" - ] - }, - { - "name": "加载超时异常", - "matchedStatuses": [ - "broken" - ], - "messageRegex": ".*TimeoutException.*" - } -] -""" -allure_results_environment_properties = '%s/environment.properties' % allure_results -allure_results_environment_properties_content = """ -OS = %s -Python = %s -Execute = %s -""" % ( - ('%s (%s %s) %s' % (platform.node(), platform.system(), platform.release(), platform.machine().lower())), - ('%s' % (platform.python_version())), - executable.replace("\\", '/') -) -is_file_exists(allure_results) and open(allure_results_categories, mode='w', encoding='utf-8').write(allure_results_categories_content) -is_file_exists(allure_results) and open(allure_results_environment_properties, mode='w', encoding='utf-8').write(allure_results_environment_properties_content) - -exit(first_command_status)