Skip to content

Commit dc18be2

Browse files
authored
Merge pull request #4 from Dark-Passenger/master
Rebased @dark-passenger's, @eestrada 's changes on latest HTMLTestRunner version 3.
2 parents 11417ae + 25329c0 commit dc18be2

File tree

4 files changed

+55
-22
lines changed

4 files changed

+55
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ This project adheres to [Semantic Versioning](http://semver.org/) and http://kee
66
### Added
77
- CHANGELOG.md from @dash0002
88

9+
## [1.0.0]
910
### Changed
1011
- Moved license content from python file to LICENSE
1112
- Updated README to reflect current state of project
1213
- Upgraded to support Python 3.4.3
1314

14-
### Changed v1.0.1
15+
## [1.0.1]
16+
### Changed
1517
- Imported select functions only rather than the entire module.
1618
- remove unused variables.
1719
- Remove string slice and use a datetime function instead.
1820
- Now compatible with python 3.5.2
1921
- Added Contributor Dark-Passenger to Readme
22+
23+
## [1.0.2]
24+
### Added
25+
- Added support for skip tests.

HTMLTestRunner.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.0.1"
1+
__version__ = "1.0.2"
22

33
from datetime import datetime
44
from io import StringIO
@@ -92,6 +92,7 @@ class Template_mixin(object):
9292
0: 'pass',
9393
1: 'fail',
9494
2: 'error',
95+
3: 'skip',
9596
}
9697

9798
DEFAULT_TITLE = 'Unit Test Report'
@@ -293,8 +294,10 @@ class Template_mixin(object):
293294
.passClass { background-color: #6c6; }
294295
.failClass { background-color: #c60; }
295296
.errorClass { background-color: #c00; }
297+
.skipClass { background-color: #ff0; }
296298
.passCase { color: #6c6; }
297299
.failCase { color: #c60; font-weight: bold; }
300+
.skipCase { color: #ff0; font-weight: bold; }
298301
.errorCase { color: #c00; font-weight: bold; }
299302
.hiddenRow { display: none; }
300303
.testcase { margin-left: 2em; }
@@ -349,6 +352,7 @@ class Template_mixin(object):
349352
<td>Test Group/Test case</td>
350353
<td>Count</td>
351354
<td>Pass</td>
355+
<td>Skip</td>
352356
<td>Fail</td>
353357
<td>Error</td>
354358
<td>View</td>
@@ -358,6 +362,7 @@ class Template_mixin(object):
358362
<td>Total</td>
359363
<td>%(count)s</td>
360364
<td>%(Pass)s</td>
365+
<td>%(skip)s</td>
361366
<td>%(fail)s</td>
362367
<td>%(error)s</td>
363368
<td>&nbsp;</td>
@@ -370,6 +375,7 @@ class Template_mixin(object):
370375
<td>%(desc)s</td>
371376
<td>%(count)s</td>
372377
<td>%(Pass)s</td>
378+
<td>%(skip)s</td>
373379
<td>%(fail)s</td>
374380
<td>%(error)s</td>
375381
<td><a href="javascript:showClassDetail('%(cid)s',%(count)s)">Detail</a></td>
@@ -435,6 +441,7 @@ def __init__(self, verbosity=1):
435441
self.stdout0 = None
436442
self.stderr0 = None
437443
self.success_count = 0
444+
self.skip_count = 0
438445
self.failure_count = 0
439446
self.error_count = 0
440447
self.verbosity = verbosity
@@ -518,6 +525,19 @@ def addFailure(self, test, err):
518525
else:
519526
sys.stderr.write('F')
520527

528+
def addSkip(self, test, err):
529+
self.skip_count += 1
530+
TestResult.addSkip(self, test, err)
531+
_exc_str = self.skipped[-1][1]
532+
output = self.complete_output()
533+
self.result.append((3, test, output, _exc_str))
534+
if self.verbosity > 1:
535+
sys.stderr.write('S ')
536+
sys.stderr.write(str(test))
537+
sys.stderr.write('\n')
538+
else:
539+
sys.stderr.write('S')
540+
521541

522542
class HTMLTestRunner(Template_mixin):
523543
"""
@@ -571,6 +591,7 @@ def getReportAttributes(self, result):
571591
duration = str(self.stopTime - self.startTime)
572592
status = []
573593
if result.success_count: status.append('Pass %s' % result.success_count)
594+
if result.skip_count: status.append('Skip %s' % result.skip_count )
574595
if result.failure_count: status.append('Failure %s' % result.failure_count)
575596
if result.error_count: status.append('Error %s' % result.error_count )
576597
if status:
@@ -627,11 +648,12 @@ def _generate_report(self, result):
627648
sortedResult = self.sortResult(result.result)
628649
for cid, (cls, cls_results) in enumerate(sortedResult):
629650
# subtotal for a class
630-
np = nf = ne = 0
651+
np = ns = nf = ne = 0
631652
for n,t,o,e in cls_results:
632653
if n == 0: np += 1
633654
elif n == 1: nf += 1
634-
else: ne += 1
655+
elif n == 2: ne += 1
656+
elif n == 3: ns += 1
635657

636658
# format class description
637659
if cls.__module__ == "__main__":
@@ -642,9 +664,9 @@ def _generate_report(self, result):
642664
desc = doc and '%s: %s' % (name, doc) or name
643665

644666
row = self.REPORT_CLASS_TMPL % dict(
645-
style = ne > 0 and 'errorClass' or nf > 0 and 'failClass' or 'passClass',
667+
style = ne > 0 and 'errorClass' or nf > 0 and 'failClass' or ns > 0 and 'skipClass' or 'passClass',
646668
desc = desc,
647-
count = np+nf+ne,
669+
count = np+ns+nf+ne,
648670
Pass = np,
649671
fail = nf,
650672
error = ne,
@@ -657,8 +679,9 @@ def _generate_report(self, result):
657679

658680
report = self.REPORT_TMPL % dict(
659681
test_list = ''.join(rows),
660-
count = str(result.success_count+result.failure_count+result.error_count),
682+
count = str(result.success_count+result.failure_count+result.error_count+result.skip_count),
661683
Pass = str(result.success_count),
684+
skip = str(result.skip_count),
662685
fail = str(result.failure_count),
663686
error = str(result.error_count),
664687
)

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ by dash0002. In it's current iteration and maintenance, our goals are still the
4343
to be able to quickly generate an HTML test report.
4444

4545
## Installation
46-
Supporting Python 3.4.3
46+
Supporting Python 3 - 3.5
4747

4848
### PIP (recommended)
4949

@@ -57,9 +57,10 @@ as-is.
5757

5858
## Contributors
5959

60-
Way Yip Tung - https://github.com/tungwaiyip
61-
Asish Dash - https://github.com/dash0002
62-
Dhruv Paranjape - https://github.com/dark-passenger
60+
- Way Yip Tung - https://github.com/tungwaiyip
61+
- Asish Dash - https://github.com/dash0002
62+
- Dhruv Paranjape - https://github.com/dark-passenger
63+
- Ethan Estrada - https://github.com/eestrada
6364

6465
Contributions are gladly accepted as this is a side project at best. Please, also
6566
consider this when looking at feedback cycles, issues, pull requests, etc.

test_HTMLTestRunner.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
# -*- coding: utf-8 -*-
22

3-
import io as StringIO
4-
import sys
5-
import unittest
6-
import HTMLTestRunner
3+
from io import StringIO
4+
from unittest import TestSuite, TestLoader, skip, TextTestRunner, TestCase
5+
from HTMLTestRunner import HTMLTestRunner
76

87
import tests
98
from tests.SampleTestPass import SampleTestPass
109
from tests.SampleTestFail import SampleTestFail
1110
from tests.SampleTestBasic import SampleTestBasic
1211

13-
class TestHTMLTestRunner(unittest.TestCase):
12+
class TestHTMLTestRunner(TestCase):
1413

1514
def setUp(self):
1615

17-
self.suite = unittest.TestSuite()
18-
self.loader = unittest.TestLoader()
16+
self.suite = TestSuite()
17+
self.loader = TestLoader()
1918

2019
self.suite.addTests(self.loader.loadTestsFromModule(tests.SampleTestPass))
2120
self.suite.addTests(self.loader.loadTestsFromModule(tests.SampleTestFail))
2221
self.suite.addTests(self.loader.loadTestsFromModule(tests.SampleTestBasic))
2322

24-
self.results_output_buffer = StringIO.StringIO()
25-
HTMLTestRunner.HTMLTestRunner(stream=self.results_output_buffer).run(self.suite)
23+
self.results_output_buffer = StringIO()
24+
HTMLTestRunner(stream=self.results_output_buffer).run(self.suite)
2625
self.byte_output = self.results_output_buffer.getvalue()
2726

2827
def test_SampleTestPass(self):
2928
output1="".join(self.byte_output.split())
3029
output2="".join(SampleTestPass.EXPECTED_RESULT.split())
3130
self.assertGreater(output1.find(output2),0)
31+
32+
@skip("Test Skipping")
33+
def test_SampleTestSkip(self):
34+
self.fail("This error should never be displayed")
3235

3336
def test_SampleTestFail(self):
3437
output1="".join(self.byte_output.split())
@@ -42,8 +45,8 @@ def test_SampleTestBasic(self):
4245

4346

4447
def main():
45-
suite = unittest.TestLoader().loadTestsFromTestCase(TestHTMLTestRunner)
46-
unittest.TextTestRunner().run(suite)
48+
suite = TestLoader().loadTestsFromTestCase(TestHTMLTestRunner)
49+
TextTestRunner().run(suite)
4750

4851
if __name__ == "__main__":
4952
main()

0 commit comments

Comments
 (0)