diff --git a/tests/builder_test.py b/tests/builder_test.py
index 5dcf5ae..cd2cf87 100644
--- a/tests/builder_test.py
+++ b/tests/builder_test.py
@@ -135,7 +135,7 @@ def test_end_root_context(self):
def test_end_nested_context(self):
self.builder.begin_context('testsuite', 'name')
- nested = self.builder.current_context()
+ self.builder.current_context()
self.assertTrue(self.builder.end_context())
@@ -187,7 +187,7 @@ def test_append_invalid_unicode_cdata_section(self):
self.assertEqual(cdata.data, self.invalid_chars_replace)
def test_append_cdata_closing_tags_into_cdata_section(self):
- self.builder.append_cdata_section('tag',']]>')
+ self.builder.append_cdata_section('tag', ']]>')
self.builder.end_context()
root_child = self.doc.childNodes[0]
cdata_container = root_child.childNodes[0]
diff --git a/tests/django_example/app/admin.py b/tests/django_example/app/admin.py
index 8c38f3f..ce2d981 100644
--- a/tests/django_example/app/admin.py
+++ b/tests/django_example/app/admin.py
@@ -1,3 +1,3 @@
-from django.contrib import admin
+from django.contrib import admin # NOQA
# Register your models here.
diff --git a/tests/django_example/app/models.py b/tests/django_example/app/models.py
index 71a8362..6cf3ee9 100644
--- a/tests/django_example/app/models.py
+++ b/tests/django_example/app/models.py
@@ -1,3 +1,3 @@
-from django.db import models
+from django.db import models # NOQA
# Create your models here.
diff --git a/tests/django_example/app/tests.py b/tests/django_example/app/tests.py
index 742d37a..232d365 100644
--- a/tests/django_example/app/tests.py
+++ b/tests/django_example/app/tests.py
@@ -1,6 +1,7 @@
from django.test import TestCase
+
# Create your tests here.
class DummyTestCase(TestCase):
def test_pass(self):
- pass
\ No newline at end of file
+ pass
diff --git a/tests/django_example/app/views.py b/tests/django_example/app/views.py
index 91ea44a..6c75fd1 100644
--- a/tests/django_example/app/views.py
+++ b/tests/django_example/app/views.py
@@ -1,3 +1,3 @@
-from django.shortcuts import render
+from django.shortcuts import render # NOQA
# Create your views here.
diff --git a/tests/django_example/app2/admin.py b/tests/django_example/app2/admin.py
index 8c38f3f..ce2d981 100644
--- a/tests/django_example/app2/admin.py
+++ b/tests/django_example/app2/admin.py
@@ -1,3 +1,3 @@
-from django.contrib import admin
+from django.contrib import admin # NOQA
# Register your models here.
diff --git a/tests/django_example/app2/models.py b/tests/django_example/app2/models.py
index 71a8362..6cf3ee9 100644
--- a/tests/django_example/app2/models.py
+++ b/tests/django_example/app2/models.py
@@ -1,3 +1,3 @@
-from django.db import models
+from django.db import models # NOQA
# Create your models here.
diff --git a/tests/django_example/app2/tests.py b/tests/django_example/app2/tests.py
index 038cc8e..232d365 100644
--- a/tests/django_example/app2/tests.py
+++ b/tests/django_example/app2/tests.py
@@ -1,5 +1,6 @@
from django.test import TestCase
+
# Create your tests here.
class DummyTestCase(TestCase):
def test_pass(self):
diff --git a/tests/django_example/app2/views.py b/tests/django_example/app2/views.py
index 91ea44a..6c75fd1 100644
--- a/tests/django_example/app2/views.py
+++ b/tests/django_example/app2/views.py
@@ -1,3 +1,3 @@
-from django.shortcuts import render
+from django.shortcuts import render # NOQA
# Create your views here.
diff --git a/tests/django_test.py b/tests/django_test.py
index 49b35cf..f113991 100644
--- a/tests/django_test.py
+++ b/tests/django_test.py
@@ -1,7 +1,6 @@
from xmlrunner.unittest import unittest
import sys
-import os
from os import path, chdir, getcwd
try:
@@ -13,8 +12,10 @@
TESTS_DIR = path.dirname(__file__)
+
@unittest.skipIf(django is None, 'django not found')
class DjangoTest(unittest.TestCase):
+
def setUp(self):
self._old_cwd = getcwd()
self.project_dir = path.abspath(path.join(TESTS_DIR, 'django_example'))
@@ -27,14 +28,14 @@ def tearDown(self):
chdir(self._old_cwd)
def _check_runner(self, runner):
- suite = runner.build_suite(test_labels=['app2','app'])
- test_ids = [ test.id() for test in suite ]
+ suite = runner.build_suite(test_labels=['app2', 'app'])
+ test_ids = [test.id() for test in suite]
self.assertEqual(test_ids, [
'app2.tests.DummyTestCase.test_pass',
'app.tests.DummyTestCase.test_pass',
])
suite = runner.build_suite(test_labels=[])
- test_ids = [ test.id() for test in suite ]
+ test_ids = [test.id() for test in suite]
self.assertEqual(set(test_ids), set([
'app.tests.DummyTestCase.test_pass',
'app2.tests.DummyTestCase.test_pass',
@@ -42,7 +43,7 @@ def _check_runner(self, runner):
def test_django_runner(self):
from django.conf import settings
- settings.configure(INSTALLED_APPS=['app','app2'])
+ settings.configure(INSTALLED_APPS=['app', 'app2'])
runner_class = get_runner(settings)
runner = runner_class()
self._check_runner(runner)
@@ -50,7 +51,7 @@ def test_django_runner(self):
def test_django_xmlrunner(self):
from django.conf import settings
settings.configure(
- INSTALLED_APPS=['app','app2'],
+ INSTALLED_APPS=['app', 'app2'],
TEST_RUNNER='xmlrunner.extra.djangotestrunner.XMLTestRunner')
runner_class = get_runner(settings)
runner = runner_class()
diff --git a/tests/testsuite.py b/tests/testsuite.py
old mode 100755
new mode 100644
index 55a0c55..3533463
--- a/tests/testsuite.py
+++ b/tests/testsuite.py
@@ -18,18 +18,20 @@
class DoctestTest(unittest.TestCase):
+
def test_doctest_example(self):
suite = doctest.DocTestSuite(tests.doctest_example)
outdir = BytesIO()
stream = StringIO()
- runner = xmlrunner.XMLTestRunner(stream=stream, output=outdir, verbosity=0)
+ runner = xmlrunner.XMLTestRunner(
+ stream=stream, output=outdir, verbosity=0)
runner.run(suite)
outdir.seek(0)
output = outdir.read()
- self.assertIn('classname="tests.doctest_example.Multiplicator" name="threetimes"'
- .encode('utf8'), output)
- self.assertIn('classname="tests.doctest_example" name="twice"'
- .encode('utf8'), output)
+ self.assertIn('classname="tests.doctest_example.Multiplicator" '
+ 'name="threetimes"'.encode('utf8'), output)
+ self.assertIn('classname="tests.doctest_example" '
+ 'name="twice"'.encode('utf8'), output)
class XMLTestRunnerTestCase(unittest.TestCase):
@@ -37,40 +39,54 @@ class XMLTestRunnerTestCase(unittest.TestCase):
XMLTestRunner test case.
"""
class DummyTest(unittest.TestCase):
+
@unittest.skip("demonstrating skipping")
def test_skip(self):
pass # pragma: no cover
+
@unittest.skip(u"demonstrating non-ascii skipping: éçà")
def test_non_ascii_skip(self):
pass # pragma: no cover
+
def test_pass(self):
pass
+
def test_fail(self):
self.assertTrue(False)
+
@unittest.expectedFailure
def test_expected_failure(self):
self.assertTrue(False)
+
@unittest.expectedFailure
def test_unexpected_success(self):
pass
+
def test_error(self):
1 / 0
+
def test_cdata_section(self):
print('')
+
def test_non_ascii_error(self):
self.assertEqual(u"éçà", 42)
+
def test_unsafe_unicode(self):
print(u"A\x00B\x08C\x0BD\x0C")
+
def test_runner_buffer_output_pass(self):
print('should not be printed')
+
def test_runner_buffer_output_fail(self):
print('should be printed')
self.fail('expected to fail')
+
def test_non_ascii_runner_buffer_output_fail(self):
print(u'Where is the café ?')
self.fail(u'The café could not be found')
class DummySubTest(unittest.TestCase):
+
def test_subTest_pass(self):
for i in range(2):
with self.subTest(i=i):
@@ -82,13 +98,16 @@ def test_subTest_fail(self):
self.fail('this is a subtest.')
class DummyErrorInCallTest(unittest.TestCase):
+
def __call__(self, result):
try:
raise Exception('Massive fail')
except Exception:
result.addError(self, sys.exc_info())
return
- super(DummyErrorInCallTest, self).__call__(result)
+ super(XMLTestRunnerTestCase.DummyErrorInCallTest, self)\
+ .__call__(result)
+
def test_pass(self):
pass
@@ -107,7 +126,7 @@ def _test_xmlrunner(self, suite, runner=None):
if runner is None:
runner = xmlrunner.XMLTestRunner(
stream=stream, output=outdir, verbosity=verbosity,
- **self.runner_kwargs)
+ **runner_kwargs)
self.assertEqual(0, len(glob(os.path.join(outdir, '*xml'))))
runner.run(suite)
self.assertEqual(1, len(glob(os.path.join(outdir, '*xml'))))
@@ -129,14 +148,17 @@ def test_classnames(self):
suite.addTest(self.DummySubTest('test_subTest_pass'))
outdir = BytesIO()
stream = StringIO()
- runner = xmlrunner.XMLTestRunner(stream=stream, output=outdir, verbosity=0)
+ runner = xmlrunner.XMLTestRunner(
+ stream=stream, output=outdir, verbosity=0)
runner.run(suite)
outdir.seek(0)
output = outdir.read()
- self.assertIn('classname="tests.testsuite.DummyTest" name="test_pass"'
- .encode('utf8'), output)
- self.assertIn('classname="tests.testsuite.DummySubTest" name="test_subTest_pass"'
- .encode('utf8'), output)
+ self.assertIn('classname="tests.testsuite.DummyTest" '
+ 'name="test_pass"'.encode('utf8'),
+ output)
+ self.assertIn('classname="tests.testsuite.DummySubTest" '
+ 'name="test_subTest_pass"'.encode('utf8'),
+ output)
def test_xmlrunner_non_ascii(self):
suite = unittest.TestSuite()
@@ -150,7 +172,8 @@ def test_xmlrunner_non_ascii(self):
outdir.seek(0)
output = outdir.read()
self.assertIn(
- u''.encode('utf8'),
+ u''.encode('utf8'),
output)
def test_xmlrunner_safe_xml_encoding_name(self):
@@ -166,21 +189,25 @@ def test_xmlrunner_safe_xml_encoding_name(self):
firstline = output.splitlines()[0]
# test for issue #74
self.assertIn('encoding="UTF-8"'.encode('utf8'), firstline)
-
+
def test_xmlrunner_check_for_valid_xml_streamout(self):
"""
This test checks if the xml document is valid if there are more than
one testsuite and the output of the report is a single stream.
"""
class DummyTestA(unittest.TestCase):
+
def test_pass(self):
pass
+
class DummyTestB(unittest.TestCase):
+
def test_pass(self):
pass
+
suite = unittest.TestSuite()
- suite.addTest( unittest.TestLoader().loadTestsFromTestCase(DummyTestA) );
- suite.addTest( unittest.TestLoader().loadTestsFromTestCase(DummyTestB) );
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(DummyTestA))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(DummyTestB))
outdir = BytesIO()
runner = xmlrunner.XMLTestRunner(
stream=self.stream, output=outdir, verbosity=self.verbosity,
@@ -188,7 +215,7 @@ def test_pass(self):
runner.run(suite)
outdir.seek(0)
output = outdir.read()
- # Finally check if we have a valid XML document or not.
+ # Finally check if we have a valid XML document or not.
try:
minidom.parseString(output)
except Exception as e:
@@ -204,11 +231,13 @@ def test_xmlrunner_unsafe_unicode(self):
runner.run(suite)
outdir.seek(0)
output = outdir.read()
- self.assertIn(u"".encode('utf8'), output)
+ self.assertIn(u"".encode('utf8'),
+ output)
def test_xmlrunner_non_ascii_failures(self):
suite = unittest.TestSuite()
- suite.addTest(self.DummyTest('test_non_ascii_runner_buffer_output_fail'))
+ suite.addTest(self.DummyTest(
+ 'test_non_ascii_runner_buffer_output_fail'))
outdir = BytesIO()
runner = xmlrunner.XMLTestRunner(
stream=self.stream, output=outdir, verbosity=self.verbosity,
@@ -243,8 +272,8 @@ def test_xmlrunner_buffer_output_fail(self):
testsuite_output = self.stream.getvalue()
self.assertIn('should be printed', testsuite_output)
- @unittest.skipIf(not hasattr(unittest.TestCase,'subTest'),
- 'unittest.TestCase.subTest not present.')
+ @unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'),
+ 'unittest.TestCase.subTest not present.')
def test_unittest_subTest_fail(self):
# test for issue #77
outdir = BytesIO()
@@ -265,7 +294,8 @@ def test_unittest_subTest_fail(self):
b'name="test_subTest_fail (i=1)"',
output)
- @unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'), 'unittest.TestCase.subTest not present.')
+ @unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'),
+ 'unittest.TestCase.subTest not present.')
def test_unittest_subTest_pass(self):
# Test for issue #85
suite = unittest.TestSuite()
@@ -283,7 +313,8 @@ def test_xmlrunner_failfast(self):
suite.addTest(self.DummyTest('test_pass'))
outdir = BytesIO()
runner = xmlrunner.XMLTestRunner(
- stream=self.stream, output=outdir, verbosity=self.verbosity, failfast=True,
+ stream=self.stream, output=outdir,
+ verbosity=self.verbosity, failfast=True,
**self.runner_kwargs)
runner.run(suite)
outdir.seek(0)
@@ -348,7 +379,8 @@ def test_junitxml_xsd_validation_order(self):
i_system_out = output.index(''.encode('utf8'))
i_system_err = output.index(''.encode('utf8'))
i_testcase = output.index('