Skip to content

Report name patch #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions HtmlTestRunner/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,13 @@ def generate_reports(self, testRunner):
**testRunner.template_args
)
# append test case name if multiple reports to be generated
if testRunner.report_name is None:
report_name_body = self.default_prefix + test_case_class_name
if testRunner.report_name is not None:
if len(all_results.values()) == 1:
report_name_body = testRunner.report_name
else:
report_name_body = "{}_{}".format(testRunner.report_name, test_case_class_name)
else:
report_name_body = "{}_{}".format(testRunner.report_name, test_case_class_name)
report_name_body = self.default_prefix + test_case_class_name
self.generate_file(testRunner, report_name_body, html_file)

else:
Expand Down
90 changes: 45 additions & 45 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
# import HtmlTestRunner
# import unittest
import HtmlTestRunner
import unittest


# class TestStringMethods(unittest.TestCase):
# """ Example test for HtmlRunner. """
class TestStringMethods(unittest.TestCase):
""" Example test for HtmlRunner. """

# def test_upper(self):
# self.assertEqual('foo'.upper(), 'FOO')
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')

# def test_isupper(self):
# self.assertTrue('FOO'.isupper())
# self.assertFalse('Foo'.isupper())
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())

# def test_split(self):
# s = 'hello world'
# self.assertEqual(s.split(), ['hello', 'world'])
# # check that s.split fails when the separator is not a string
# with self.assertRaises(TypeError):
# s.split(2)
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)

# def test_error(self):
# """ This test should be marked as error one. """
# raise ValueError
def test_error(self):
""" This test should be marked as error one. """
raise ValueError

# def test_fail(self):
# """ This test should fail. """
# self.assertEqual(1, 2)
def test_fail(self):
""" This test should fail. """
self.assertEqual(1, 2)

# @unittest.skip("This is a skipped test.")
# def test_skip(self):
# """ This test should be skipped. """
# pass
@unittest.skip("This is a skipped test.")
def test_skip(self):
""" This test should be skipped. """
pass

# def test_subs_fail(self):
# test_string = "test1"
# for i, char in enumerate(test_string):
# with self.subTest(i=i):
# self.assertEqual(char, "1")
def test_subs_fail(self):
test_string = "test1"
for i, char in enumerate(test_string):
with self.subTest(i=i):
self.assertEqual(char, "1")

# with self.subTest(test_string=test_string):
# # subtests that error will appear as a failure presently
# raise AttributeError
with self.subTest(test_string=test_string):
# subtests that error will appear as a failure presently
raise AttributeError


# class MoreTests(unittest.TestCase):
# def test_1(self):
# print("This is different to test2.MoreTests.test_1")
# self.assertEqual(100, -100)
class MoreTests(unittest.TestCase):
def test_1(self):
print("This is different to test2.MoreTests.test_1")
self.assertEqual(100, -100)


# if __name__ == '__main__':
# unittest.main(
# testRunner=HtmlTestRunner.HTMLTestRunner(
# open_in_browser=True,
# combine_reports=True,
# template_args={}
# )
# )
if __name__ == '__main__':
unittest.main(
testRunner=HtmlTestRunner.HTMLTestRunner(
open_in_browser=True,
combine_reports=True,
template_args={}
)
)
149 changes: 79 additions & 70 deletions tests/test2.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,79 @@
# import unittest

# from HtmlTestRunner import HTMLTestRunner

# from test import TestStringMethods
# from test import MoreTests as MoreTests_


# class My_Tests(unittest.TestCase):

# def test_one(self):
# self.assertTrue(True)

# def test_two(self):
# # demonstrate that stdout is captured in passing tests
# print("HOLA CARACOLA")
# self.assertTrue(True)

# def test_three(self):
# self.assertTrue(True)

# def test_1(self):
# # demonstrate that stdout is captured in failing tests
# print("HELLO")
# self.assertTrue(False)

# def test_2(self):
# self.assertTrue(False)

# def test_3(self):
# self.assertTrue(False)

# def test_z_subs_pass(self):
# for i in range(2):
# with self.subTest(i=i):
# print("i = {}".format(i)) # this won't appear for now
# self.assertEqual(i, i)


# class MoreTests(unittest.TestCase):
# def test_1(self):
# print("This is different to test.MoreTests.test_1")
# self.assertAlmostEqual(1, 1.1, delta=0.05)


# if __name__ == '__main__':
# tests = unittest.TestLoader().loadTestsFromTestCase(My_Tests)
# other_tests = unittest.TestLoader().loadTestsFromTestCase(TestStringMethods)
# more_tests = unittest.TestLoader().loadTestsFromTestCase(MoreTests)
# more_tests_ = unittest.TestLoader().loadTestsFromTestCase(MoreTests_)
# suite = unittest.TestSuite([tests, other_tests, more_tests, more_tests_])
# HTMLTestRunner(
# report_title='TEST COMBINED',
# report_name="MyReports",
# add_timestamp=False,
# open_in_browser=True,
# combine_reports=True
# ).run(suite)

# tests = unittest.TestLoader().loadTestsFromTestCase(My_Tests)
# other_tests = unittest.TestLoader().loadTestsFromTestCase(TestStringMethods)
# more_tests = unittest.TestLoader().loadTestsFromTestCase(MoreTests)
# more_tests_ = unittest.TestLoader().loadTestsFromTestCase(MoreTests_)
# suite = unittest.TestSuite([tests, other_tests, more_tests, more_tests_])
# HTMLTestRunner(
# report_title='TEST SEPARATE',
# report_name="MyReports",
# open_in_browser=True,
# combine_reports=False
# ).run(suite)
import unittest

from HtmlTestRunner import HTMLTestRunner

from test import TestStringMethods
from test import MoreTests as MoreTests_


class My_Tests(unittest.TestCase):

def test_one(self):
self.assertTrue(True)

def test_two(self):
# demonstrate that stdout is captured in passing tests
print("HOLA CARACOLA")
self.assertTrue(True)

def test_three(self):
self.assertTrue(True)

def test_1(self):
# demonstrate that stdout is captured in failing tests
print("HELLO")
self.assertTrue(False)

def test_2(self):
self.assertTrue(False)

def test_3(self):
self.assertTrue(False)

def test_z_subs_pass(self):
for i in range(2):
with self.subTest(i=i):
print("i = {}".format(i)) # this won't appear for now
self.assertEqual(i, i)


class MoreTests(unittest.TestCase):
def test_1(self):
print("This is different to test.MoreTests.test_1")
self.assertAlmostEqual(1, 1.1, delta=0.05)


if __name__ == '__main__':
tests = unittest.TestLoader().loadTestsFromTestCase(My_Tests)
other_tests = unittest.TestLoader().loadTestsFromTestCase(TestStringMethods)
more_tests = unittest.TestLoader().loadTestsFromTestCase(MoreTests)
more_tests_ = unittest.TestLoader().loadTestsFromTestCase(MoreTests_)
suite0 = unittest.TestSuite([tests, other_tests, more_tests, more_tests_])
HTMLTestRunner(
report_title='TEST COMBINED',
report_name="MyReports",
add_timestamp=False,
open_in_browser=True,
combine_reports=True
).run(suite0)

tests = unittest.TestLoader().loadTestsFromTestCase(My_Tests)
other_tests = unittest.TestLoader().loadTestsFromTestCase(TestStringMethods)
more_tests = unittest.TestLoader().loadTestsFromTestCase(MoreTests)
more_tests_ = unittest.TestLoader().loadTestsFromTestCase(MoreTests_)
suite1 = unittest.TestSuite([tests, other_tests, more_tests, more_tests_])
HTMLTestRunner(
report_title='TEST SEPARATE',
report_name="MyReports",
open_in_browser=True,
combine_reports=False
).run(suite1)

tests = unittest.TestLoader().loadTestsFromTestCase(My_Tests)
suite2 = unittest.TestSuite([tests])
HTMLTestRunner(
report_title='SINGLE TEST',
report_name="MySingleReport",
open_in_browser=True,
combine_reports=False
).run(suite2)