forked from tungwaiyip/HTMLTestRunner
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests.py
87 lines (68 loc) · 2.31 KB
/
tests.py
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
76
77
78
79
80
81
82
83
84
85
86
87
import unittest
import HTMLTestRunner
class PassTestCase(unittest.TestCase):
def test_pass(self):
"""A test that passes"""
print 'test_pass'
self.assertTrue(True)
class FailTestCase(unittest.TestCase):
def test_fail(self):
"""A test that fails"""
print 'test_fail'
self.assertTrue(False)
class ErrorTestCase(unittest.TestCase):
def test_error(self):
"""A test that raise an exception"""
print 'test_error'
raise Exception
class SkipBeforeTestMethodTestCase(unittest.TestCase):
@unittest.skip('Skip before test method')
def test_skip_before_test_method(self):
print 'test_skip_before_test_method'
pass
class SkipInsideTestMethodTestCase(unittest.TestCase):
def test_skip_inside_test_method(self):
print 'test_skip_inside_test_method'
self.skipTest('Skip inside test method')
@unittest.skip('Skip class')
class SkipClassTestCase(unittest.TestCase):
def test_skip_class(self):
print 'test_skip_class'
pass
def fake_attrs():
g2attrs = [
('My Project Name', 'Fake Project Name'),
('Reponsible Team', 'Fake Team'),
('Build Number', '42'),
]
g3attrs = [
('Produc Under Test', 'The Fake Product Site'),
('Product Team', 'Fake Product Team')
]
attrs = {'group2': g2attrs, 'group3': g3attrs}
return attrs
def fake_description():
desc = """This is a fake description
divided in two lines."""
return desc
if __name__ == '__main__':
# Create the report file
html_report = open('sample_test_report.html', 'w')
# Create the runner and set the file as output and higher verbosity
runner = HTMLTestRunner.HTMLTestRunner(stream=html_report, verbosity=2, attrs=fake_attrs(),
description=fake_description())
# Create a test list
tests = [
ErrorTestCase, FailTestCase, PassTestCase, SkipBeforeTestMethodTestCase, SkipClassTestCase,
SkipInsideTestMethodTestCase
]
# Load test cases
loader = unittest.TestLoader()
# Create a SuiteCase
test_list = []
for test in tests:
cases = loader.loadTestsFromTestCase(test)
test_list.append(cases)
suite = unittest.TestSuite(test_list)
# Run the suite
runner.run(suite)