-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathredfishUnittest.py
More file actions
75 lines (61 loc) · 2.61 KB
/
redfishUnittest.py
File metadata and controls
75 lines (61 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#
# Do NOT modify or remove this copyright and license
#
# Copyright (c) 2019 Seagate Technology LLC and/or its Affiliates, All Rights Reserved
#
# This software is subject to the terms of the MIT License. If a copy of the license was
# not distributed with this file, you can obtain one at https://opensource.org/licenses/MIT.
#
# ******************************************************************************************
#
# redfishUnittest.py - Module to run and report on all unit tests.
#
# ******************************************************************************************
#
from core.label import Label
from core.trace import TraceLevel, Trace
import argparse
import config
import sys
import unittest
import HtmlTestRunner
import xmlrunner
################################################################################
# main()
################################################################################
if __name__ == '__main__':
print('')
print('-' * 80)
print('[] Redfish Unit Tests')
print('-' * 80)
returncode = 0
redfishUnittestEpilog = '''Examples:
>> Run Redfish unit tests and generate an HTML report.
python redfishUnittest.py --html
>> Run Redfish unit tests and generate an XML report.
python redfishUnittest.py --xml
'''
parser = argparse.ArgumentParser(
description='Run Seagate Systems Redfish unit tests and generate a report.',
epilog=redfishUnittestEpilog,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-c', '--config', help='Specify the Redfish API JSON configuration file.')
parser.add_argument('--html', help='Generate an HTML unit test report', action='store_true', required=False)
parser.add_argument('--xml', help='Generate an XML unit test report', action='store_true')
args = parser.parse_args()
Label.encode(config.sessionConfig, config.defaultConfigFile if args.config == None else args.config)
extension = ''
testFiles = 'test*.py'
if (args.xml):
Trace.log(TraceLevel.INFO, '++ Generate XML Report')
extension = 'xml'
tests = unittest.TestLoader().discover(config.testFolder, pattern=testFiles)
testRunner = xmlrunner.XMLTestRunner(output=config.reportFolder)
testRunner.run(tests)
else:
Trace.log(TraceLevel.INFO, '++ Generate HTML Report')
extension = 'html'
tests = unittest.TestLoader().discover(config.testFolder, pattern=testFiles)
testRunner = HtmlTestRunner.HTMLTestRunner(combine_reports=True, open_in_browser=True, add_timestamp=True)
testRunner.run(tests)
sys.exit(returncode)