From 5664647967d27ebf24aad1722b02ba0b722d9575 Mon Sep 17 00:00:00 2001 From: Brett Buford Date: Thu, 8 Sep 2022 08:25:09 -0700 Subject: [PATCH] Fixed AttributeError upon a single skipped test --- tests/django_example/app3/__init__.py | 0 tests/django_example/app3/admin.py | 3 +++ tests/django_example/app3/migrations/__init__.py | 0 tests/django_example/app3/models.py | 3 +++ tests/django_example/app3/tests.py | 12 ++++++++++++ tests/django_example/app3/views.py | 3 +++ tests/django_example/example/settings.py | 2 +- tests/django_test.py | 6 ++++-- xmlrunner/result.py | 2 +- 9 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 tests/django_example/app3/__init__.py create mode 100644 tests/django_example/app3/admin.py create mode 100644 tests/django_example/app3/migrations/__init__.py create mode 100644 tests/django_example/app3/models.py create mode 100644 tests/django_example/app3/tests.py create mode 100644 tests/django_example/app3/views.py diff --git a/tests/django_example/app3/__init__.py b/tests/django_example/app3/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/django_example/app3/admin.py b/tests/django_example/app3/admin.py new file mode 100644 index 0000000..ce2d981 --- /dev/null +++ b/tests/django_example/app3/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin # NOQA + +# Register your models here. diff --git a/tests/django_example/app3/migrations/__init__.py b/tests/django_example/app3/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/django_example/app3/models.py b/tests/django_example/app3/models.py new file mode 100644 index 0000000..6cf3ee9 --- /dev/null +++ b/tests/django_example/app3/models.py @@ -0,0 +1,3 @@ +from django.db import models # NOQA + +# Create your models here. diff --git a/tests/django_example/app3/tests.py b/tests/django_example/app3/tests.py new file mode 100644 index 0000000..3b27554 --- /dev/null +++ b/tests/django_example/app3/tests.py @@ -0,0 +1,12 @@ +from unittest import skipIf + +from django.test import TestCase + + +# Create your tests here. +@skipIf(condition=True, reason=True) +class SkipTestCase(TestCase): + def test_skip(self): + """Test Skip""" + pass + diff --git a/tests/django_example/app3/views.py b/tests/django_example/app3/views.py new file mode 100644 index 0000000..6c75fd1 --- /dev/null +++ b/tests/django_example/app3/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render # NOQA + +# Create your views here. diff --git a/tests/django_example/example/settings.py b/tests/django_example/example/settings.py index 1f69f09..251bbfc 100644 --- a/tests/django_example/example/settings.py +++ b/tests/django_example/example/settings.py @@ -6,7 +6,7 @@ SECRET_KEY = 'not-a-secret' DEBUG = True ALLOWED_HOSTS = [] -INSTALLED_APPS = ['app', 'app2'] +INSTALLED_APPS = ['app', 'app2', 'app3'] MIDDLEWARE_CLASSES = [] ROOT_URLCONF = 'example.urls' TEMPLATES = [] diff --git a/tests/django_test.py b/tests/django_test.py index 16b4a72..261f6b2 100644 --- a/tests/django_test.py +++ b/tests/django_test.py @@ -53,9 +53,10 @@ def _override_settings(self, **kwargs): setattr(self.override, key, new_value) def _check_runner(self, runner): - suite = runner.build_suite(test_labels=['app2', 'app']) + suite = runner.build_suite(test_labels=['app3', 'app2', 'app']) test_ids = [test.id() for test in suite] self.assertEqual(test_ids, [ + 'app3.tests.SkipTestCase.test_skip', 'app2.tests.DummyTestCase.test_pass', 'app.tests.DummyTestCase.test_negative_comment1', 'app.tests.DummyTestCase.test_negative_comment2', @@ -68,6 +69,7 @@ def _check_runner(self, runner): 'app.tests.DummyTestCase.test_negative_comment1', 'app.tests.DummyTestCase.test_negative_comment2', 'app2.tests.DummyTestCase.test_pass', + 'app3.tests.SkipTestCase.test_skip', ])) def test_django_runner(self): @@ -135,7 +137,7 @@ def test_django_multiple_reports(self): test_files = glob.glob(path.join(self.tmpdir, 'TEST*.xml')) self.assertTrue(test_files, 'did not generate xml reports where expected.') - self.assertEqual(2, len(test_files)) + self.assertEqual(3, len(test_files)) def test_django_runner_extension(self): from xmlrunner.extra.djangotestrunner import XMLTestRunner diff --git a/xmlrunner/result.py b/xmlrunner/result.py index 96fc675..9a4b1ab 100644 --- a/xmlrunner/result.py +++ b/xmlrunner/result.py @@ -593,7 +593,7 @@ def _report_testcase(test_result, xml_testsuite, xml_document): ) result_elem.setAttribute( 'message', - test_result.test_exception_message + str(test_result.test_exception_message) ) if test_result.get_error_info(): error_info = safe_unicode(test_result.get_error_info())