Skip to content
Merged
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
10 changes: 3 additions & 7 deletions tests/django_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from xmlrunner.unittest import unittest

import sys
Expand All @@ -9,9 +8,12 @@
import django
except ImportError:
django = None
else:
from django.test.utils import get_runner

TESTS_DIR = path.dirname(__file__)

@unittest.skipIf(django is None, 'django not found')
class DjangoTest(unittest.TestCase):
def setUp(self):
self._old_cwd = getcwd()
Expand All @@ -20,11 +22,9 @@ def setUp(self):
sys.path.append(self.project_dir)
import django.conf
django.conf.settings = django.conf.LazySettings()
# os.environ['DJANGO_SETTINGS_MODULE'] = 'django_example.settings'

def tearDown(self):
chdir(self._old_cwd)
# del os.environ['DJANGO_SETTINGS_MODULE']

def _check_runner(self, runner):
suite = runner.build_suite(test_labels=['app2','app'])
Expand All @@ -40,22 +40,18 @@ def _check_runner(self, runner):
'app2.tests.DummyTestCase.test_pass',
]))

@unittest.skipIf(django is None, 'django not found')
def test_django_runner(self):
from django.conf import settings
settings.configure(INSTALLED_APPS=['app','app2'])
from django.test.utils import get_runner
runner_class = get_runner(settings)
runner = runner_class()
self._check_runner(runner)

@unittest.skipIf(django is None, 'django not found')
def test_django_xmlrunner(self):
from django.conf import settings
settings.configure(
INSTALLED_APPS=['app','app2'],
TEST_RUNNER='xmlrunner.extra.djangotestrunner.XMLTestRunner')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests are failing because of the configure step now; probably due to global state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept the inner imports for now.

from django.test.utils import get_runner
runner_class = get_runner(settings)
runner = runner_class()
self._check_runner(runner)
7 changes: 3 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[tox]
envlist = begin,py{26,27,33,34},py27-django{lts,prev,curr},end,quality
envlist = begin,py{26,27,33,34},py27-django{lts,curr},end,quality

[testenv]
deps =
coverage
djangolts: django==1.4.22
djangoprev: django==1.6.11
djangocurr: django==1.7.10
djangolts: django==1.8.7
djangocurr: django==1.9
commands =
coverage run --append setup.py test
coverage report --omit='.tox/*'
Expand Down
14 changes: 2 additions & 12 deletions xmlrunner/extra/djangotestrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@
"""

import xmlrunner
import django
from django.conf import settings
from django.test.runner import DiscoverRunner

# future compatibilty with django
# in django 1.6 DiscoverRunner bacame default and
# DjangoTestSuiteRunner became depecated, will be removed in 1.8
if django.VERSION < (1, 6):
from django.test.simple import DjangoTestSuiteRunner
_DjangoRunner = DjangoTestSuiteRunner
else:
from django.test.runner import DiscoverRunner
_DjangoRunner = DiscoverRunner


class XMLTestRunner(_DjangoRunner):
class XMLTestRunner(DiscoverRunner):

def run_suite(self, suite, **kwargs):
dummy = kwargs # unused
Expand Down