Skip to content

Commit b9feb41

Browse files
committed
Customer request to add in option to generate the JUnit report paths like they had been in v0.76. Customer developed scripts failing for them based on the new URL of the test cases
1 parent a3fc164 commit b9feb41

File tree

2 files changed

+84
-50
lines changed

2 files changed

+84
-50
lines changed

src/main/resources/scripts/generate-results.py

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def delete_file(filename):
231231
if os.path.exists(filename):
232232
os.remove(filename)
233233

234-
def genDataApiReports(FullManageProjectName, entry, cbtDict, generate_exec_rpt_each_testcase, use_archive_extract, report_only_failures, useStartLine, teePrint):
234+
def genDataApiReports(FullManageProjectName, entry, cbtDict, generate_exec_rpt_each_testcase, use_archive_extract, report_only_failures, useStartLine, teePrint, use_cte):
235235
xml_file = ""
236236

237237
try:
@@ -262,7 +262,8 @@ def genDataApiReports(FullManageProjectName, entry, cbtDict, generate_exec_rpt_e
262262
report_only_failures,
263263
print_exc,
264264
useStartLine,
265-
teePrint)
265+
teePrint,
266+
use_cte)
266267

267268
if xml_file.api != None:
268269
if verbose:
@@ -390,7 +391,7 @@ def generateIndividualReports(entry, envName):
390391

391392

392393

393-
def useManageAPI(FullManageProjectName, cbtDict, generate_exec_rpt_each_testcase, use_archive_extract, report_only_failures, no_full_report, useStartLine, teePrint):
394+
def useManageAPI(FullManageProjectName, cbtDict, generate_exec_rpt_each_testcase, use_archive_extract, report_only_failures, no_full_report, useStartLine, teePrint, use_cte):
394395
global verbose
395396

396397
print("Using VCProjectApi")
@@ -408,7 +409,7 @@ def useManageAPI(FullManageProjectName, cbtDict, generate_exec_rpt_each_testcase
408409
report_only_failures,
409410
no_full_report,
410411
print_exc,
411-
useStartLine, teePrint)
412+
useStartLine, teePrint, use_cte)
412413

413414
if xml_file.api != None:
414415
xml_file.generate_testresults()
@@ -434,7 +435,7 @@ def useManageAPI(FullManageProjectName, cbtDict, generate_exec_rpt_each_testcase
434435
return 0, 0
435436

436437

437-
def useNewAPI(FullManageProjectName, manageEnvs, level, envName, cbtDict, generate_exec_rpt_each_testcase, use_archive_extract, report_only_failures, no_full_report, useStartLine, teePrint):
438+
def useNewAPI(FullManageProjectName, manageEnvs, level, envName, cbtDict, generate_exec_rpt_each_testcase, use_archive_extract, report_only_failures, no_full_report, useStartLine, teePrint, use_cte):
438439

439440
failed_count = 0
440441
passed_count = 0
@@ -447,7 +448,7 @@ def useNewAPI(FullManageProjectName, manageEnvs, level, envName, cbtDict, genera
447448
continue
448449

449450
if envName == None:
450-
pc, fc = genDataApiReports(FullManageProjectName, manageEnvs[currentEnv], cbtDict, generate_exec_rpt_each_testcase,use_archive_extract, report_only_failures, useStartLine, teePrint)
451+
pc, fc = genDataApiReports(FullManageProjectName, manageEnvs[currentEnv], cbtDict, generate_exec_rpt_each_testcase,use_archive_extract, report_only_failures, useStartLine, teePrint, use_cte)
451452
passed_count += pc
452453
failed_count += fc
453454
if not no_full_report:
@@ -457,7 +458,7 @@ def useNewAPI(FullManageProjectName, manageEnvs, level, envName, cbtDict, genera
457458
env_level = manageEnvs[currentEnv]["compiler"] + "/" + manageEnvs[currentEnv]["testsuite"]
458459

459460
if level == None or env_level.upper() == level.upper():
460-
pc, fc = genDataApiReports(FullManageProjectName, manageEnvs[currentEnv], cbtDict, generate_exec_rpt_each_testcase,use_archive_extract, report_only_failures, useStartLine, teePrint)
461+
pc, fc = genDataApiReports(FullManageProjectName, manageEnvs[currentEnv], cbtDict, generate_exec_rpt_each_testcase,use_archive_extract, report_only_failures, useStartLine, teePrint, use_cte)
461462
passed_count += pc
462463
failed_count += fc
463464

@@ -481,10 +482,21 @@ def cleanupOldBuilds(teePrint):
481482
# envName and level only supplied when doing reports for a sub-project
482483
# of a multi-job
483484
# def buildReports(FullManageProjectName = None, level = None, envName = None, generate_individual_reports = True, timing = False, cbtDict = None,use_archive_extract = False, report_only_failures = False, no_full_report = False):
484-
def buildReports(FullManageProjectName = None, level = None, envName = None, generate_individual_reports = True,
485-
timing = False, cbtDict = None, use_archive_extract = False,
486-
report_only_failures = False, no_full_report = False, use_ci = "", xml_data_dir = "xml_data", useStartLine = False, teePrint = None):
487-
485+
def buildReports(FullManageProjectName = None,
486+
level = None,
487+
envName = None,
488+
generate_individual_reports = True,
489+
timing = False,
490+
cbtDict = None,
491+
use_archive_extract = False,
492+
report_only_failures = False,
493+
no_full_report = False,
494+
use_ci = "",
495+
xml_data_dir = "xml_data",
496+
useStartLine = False,
497+
teePrint = None,
498+
use_cte = False):
499+
488500
if timing:
489501
print("Start report generation: " + str(time.time()))
490502

@@ -543,19 +555,19 @@ def buildReports(FullManageProjectName = None, level = None, envName = None, gen
543555

544556
if use_manage_api:
545557
passed_count, failed_count = useManageAPI(FullManageProjectName, cbtDict, generate_individual_reports,
546-
use_archive_extract,
547-
report_only_failures,
548-
no_full_report,
549-
useStartLine,
550-
teePrint)
558+
use_archive_extract, report_only_failures, no_full_report,
559+
useStartLine, teePrint, use_cte)
551560

552561
else:
553562

554563
manageEnvs = getManageEnvs(FullManageProjectName)
555564
if timing:
556565
print("Using DataAPI for reporting")
557566
print("Get Info: " + str(time.time()))
558-
passed_count, failed_count = useNewAPI(FullManageProjectName, manageEnvs, level, envName, cbtDict, generate_individual_reports, use_archive_extract, report_only_failures, no_full_report, useStartLine, teePrint)
567+
passed_count, failed_count = useNewAPI(FullManageProjectName,
568+
manageEnvs, level, envName, cbtDict, generate_individual_reports,
569+
use_archive_extract, report_only_failures, no_full_report, useStartLine,
570+
teePrint, use_cte)
559571

560572
with open("unit_test_fail_count.txt", "w") as fd:
561573
failed_str = str(failed_count)
@@ -777,29 +789,33 @@ def buildReports(FullManageProjectName = None, level = None, envName = None, gen
777789
if __name__ == '__main__':
778790

779791
parser = argparse.ArgumentParser()
780-
parser.add_argument('ManageProject', help='Manager Project Name')
781-
parser.add_argument('-v', '--verbose', help='Enable verbose output', action="store_true")
782-
parser.add_argument('-l', '--level', help='Environment Name if only doing single environment. Should be in the form of level/env')
783-
parser.add_argument('-e', '--environment', help='Environment Name if only doing single environment. Should be in the form of level/env')
784-
parser.add_argument('-g', '--dont-generate-individual-reports', help='Don\'t Generated Individual Reports (below 2019 - this just controls execution report generate, 2019 and later - execution reports for each testcase won\'t be generated', action="store_true", default=False)
785-
parser.add_argument('--wait_time', help='Time (in seconds) to wait between execution attempts', type=int, default=30)
786-
parser.add_argument('--wait_loops', help='Number of times to retry execution', type=int, default=1)
787-
parser.add_argument('--timing', help='Display timing information for report generation', action="store_true", default = False)
788-
parser.add_argument('--junit', help='Output test results in JUnit format', action="store_true")
789-
parser.add_argument('--print_exc', help='Output test results in JUnit format', action="store_true")
790-
parser.add_argument('--api', help='Unused', type=int)
791-
parser.add_argument('--use_archive_extract', help='Uses Archive/Extract for reports to save time on report generation', action="store_true", default = False)
792-
parser.add_argument('--report_only_failures', help='Report only failed test cases', action="store_true", default = False)
793-
parser.add_argument('--no_full_report', help='Generate just metrics for jenkins consumption', action="store_true", default = False)
794-
795-
parser.add_argument('--legacy', help='Force legacy reports for testing only', action="store_true", default = False)
796-
parser.add_argument('--buildlog', help='Build Log for CBT Statitics', default = None)
792+
parser.add_argument('ManageProject', help='Manager Project Name')
793+
parser.add_argument('-v', '--verbose', help='Enable verbose output', action="store_true")
794+
parser.add_argument('-l', '--level', help='Environment Name if only doing single environment. Should be in the form of level/env')
795+
parser.add_argument('-e', '--environment', help='Environment Name if only doing single environment. Should be in the form of level/env')
796+
parser.add_argument('-g', '--dont-generate-individual-reports',
797+
help='Don\'t Generated Individual Reports. Below VC2019 - this just controls execution report generate. VC2019 and later - execution reports for each testcase won\'t be generated', action="store_true", default=False)
798+
parser.add_argument('--wait_time', help='Time (in seconds) to wait between execution attempts', type=int, default=30)
799+
parser.add_argument('--wait_loops', help='Number of times to retry execution', type=int, default=1)
800+
parser.add_argument('--timing', help='Display timing information for report generation', action="store_true", default = False)
801+
parser.add_argument('--buildlog', help='Build Log for CBT Statitics', default = None)
802+
803+
## Hidden because they are specific to customer need or testing
804+
parser.add_argument('--junit', help=argparse.SUPPRESS, action="store_true")
805+
parser.add_argument('--junit_use_cte_for_classname', help=argparse.SUPPRESS, action="store_true", dest="use_cte")
806+
parser.add_argument('--print_exc', help=argparse.SUPPRESS, action="store_true")
807+
parser.add_argument('--api', help=argparse.SUPPRESS, type=int)
808+
parser.add_argument('--use_archive_extract', help=argparse.SUPPRESS, action="store_true", default = False)
809+
parser.add_argument('--report_only_failures', help=argparse.SUPPRESS, action="store_true", default = False)
810+
parser.add_argument('--no_full_report', help=argparse.SUPPRESS, action="store_true", default = False)
811+
parser.add_argument('--legacy', help=argparse.SUPPRESS, action="store_true", default = False)
797812

798813
args = parser.parse_args()
799814

800815
if args.use_archive_extract and (not args.buildlog or not os.path.exists(args.buildlog)):
801816
print("Must have a valid --buildlog file to use --use_archive_extract")
802817
print("The option use_archive_extract is disabled")
818+
args.use_archive_extract = False
803819

804820
legacy = args.legacy
805821
timing = args.timing
@@ -836,16 +852,14 @@ def new_init(self):
836852

837853
if args.verbose:
838854
verbose = True
839-
if args.print_exc:
855+
856+
if args.print_exc or verbose:
840857
print_exc = True
858+
841859
wait_time = args.wait_time
842860
wait_loops = args.wait_loops
843861

844-
if args.junit:
845-
junit = True
846-
else:
847-
print ("Test results reporting has been migrated to JUnit. If you are using older xUnit plugin with Single Jobs, please switch to using JUnit. If you need assistance with that, contact [email protected]")
848-
junit = True
862+
junit = True
849863

850864

851865
if args.buildlog and os.path.exists(args.buildlog):
@@ -871,7 +885,20 @@ def new_init(self):
871885
os.environ['VCAST_MANAGE_PROJECT_DIRECTORY'] = os.path.abspath(args.ManageProject).rsplit(".",1)[0]
872886

873887
with tee_print.TeePrint() as teePrint:
874-
buildReports(args.ManageProject,args.level,args.environment,generate_individual_reports, timing, cbtDict, args.use_archive_extract, args.report_only_failures, args.no_full_report, teePrint)
888+
buildReports(args.ManageProject,
889+
args.level,
890+
args.environment,
891+
generate_individual_reports,
892+
timing,
893+
cbtDict,
894+
args.use_archive_extract,
895+
args.report_only_failures,
896+
args.no_full_report,
897+
use_ci = "",
898+
xml_data_dir = "xml_data",
899+
useStartLine = False,
900+
teePrint = teePrint,
901+
use_cte = args.use_cte)
875902

876903
import archive_extract_reports
877904

src/main/resources/scripts/generate_xml.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def dummy(*args, **kwargs):
7070
# (Emma based) report for Coverage
7171
#
7272
class BaseGenerateXml(object):
73-
def __init__(self, FullManageProjectName, verbose, teePrint):
73+
def __init__(self, FullManageProjectName, verbose, teePrint, use_cte):
7474
projectName = os.path.splitext(os.path.basename(FullManageProjectName))[0]
7575
self.manageProjectName = projectName
7676
self.cover_report_name = os.path.join("xml_data","coverage_results_"+ self.manageProjectName + ".xml")
@@ -79,6 +79,7 @@ def __init__(self, FullManageProjectName, verbose, teePrint):
7979
self.has_sfp_enabled = False
8080
self.print_exc = False
8181
self.teePrint = teePrint
82+
self.use_cte = use_cte
8283

8384
# get the VC langaguge and encoding
8485
self.encFmt = 'utf-8'
@@ -648,9 +649,10 @@ def __init__(self, FullManageProjectName, verbose = False,
648649
no_full_reports = False,
649650
print_exc = False,
650651
useStartLine = False,
651-
teePrint = None):
652+
teePrint = None,
653+
use_cte = False):
652654

653-
super(GenerateManageXml, self).__init__(FullManageProjectName, verbose, teePrint)
655+
super(GenerateManageXml, self).__init__(FullManageProjectName, verbose, teePrint, use_cte)
654656
self.api = VCProjectApi(FullManageProjectName)
655657

656658
try:
@@ -997,8 +999,10 @@ def generate_testresults(self):
997999
#
9981000
class GenerateXml(BaseGenerateXml):
9991001

1000-
def __init__(self, FullManageProjectName, build_dir, env, compiler, testsuite, cover_report_name, jenkins_name, unit_report_name, jenkins_link, jobNameDotted, verbose = False, cbtDict= None, generate_exec_rpt_each_testcase = True, use_archive_extract = False, report_failed_only = False, print_exc = False, useStartLine = False, teePrint = None):
1001-
super(GenerateXml, self).__init__(FullManageProjectName, verbose, teePrint)
1002+
def __init__(self, FullManageProjectName, build_dir, env, compiler, testsuite, cover_report_name, jenkins_name, unit_report_name, jenkins_link, jobNameDotted, verbose = False, cbtDict= None, generate_exec_rpt_each_testcase = True,
1003+
use_archive_extract = False, report_failed_only = False, print_exc = False, useStartLine = False, teePrint = None, use_cte = False):
1004+
1005+
super(GenerateXml, self).__init__(FullManageProjectName, verbose, teePrint, use_cte)
10021006

10031007
self.cbtDict = cbtDict
10041008
self.FullManageProjectName = FullManageProjectName
@@ -1253,7 +1257,7 @@ def testcase_failed(self, tc):
12531257

12541258
def get_xml_string(self, fpath = None):
12551259

1256-
if fpath:
1260+
if False: #fpath:
12571261
testcaseStringExtraStatus="""
12581262
<testcase name="%s" classname="%s" time="%s" file="%s" line="%s">
12591263
%s
@@ -1271,7 +1275,7 @@ def get_xml_string(self, fpath = None):
12711275

12721276
else:
12731277
testcaseStringExtraStatus="""
1274-
<testcase name="%s" classname="%s" time="%s" %s %s>
1278+
<testcase name="%s" classname="%s" time="%s" file="%s" line="%s">
12751279
%s
12761280
<system-out>
12771281
%s
@@ -1292,7 +1296,7 @@ def write_testcase(self, tc, unit_name, func_name, st_is_monitored = False, unit
12921296
fpath = ""
12931297
startLine = ""
12941298
unitName = ""
1295-
1299+
12961300
if unit:
12971301
try:
12981302
filePath = unit.sourcefile.normalized_path(normcase=False)
@@ -1374,7 +1378,7 @@ def write_testcase(self, tc, unit_name, func_name, st_is_monitored = False, unit
13741378
tc_name_full = unit_name + "." + func_name + "." + tc_name
13751379

13761380
classname = compiler + "." + testsuite + "." + envName
1377-
1381+
13781382
if isSystemTest:
13791383
exp_total = tc.total
13801384
exp_pass = tc.passed
@@ -1438,6 +1442,9 @@ def write_testcase(self, tc, unit_name, func_name, st_is_monitored = False, unit
14381442

14391443
testcaseString, testcaseStringExtraStatus = self.get_xml_string(fpath)
14401444

1445+
if self.use_cte:
1446+
unitName = classname
1447+
14411448
if status != "":
14421449
msg = "{} {} / {} \n\nExecution Report:\n {}".format(status, exp_pass, exp_total, result)
14431450
msg = escape(msg, quote=False)

0 commit comments

Comments
 (0)