Skip to content

Commit 14fa2ff

Browse files
rubenduradnozay
authored andcommitted
Fixes #146
Using TEST_OUTPUT_FILE_NAME with Django does not create intermediate folders specified in TEST_OUTPUT_DIR Now it creates intermediate folders if they don't exist. Includes tests.
1 parent d70a9b2 commit 14fa2ff

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/django_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ def test_django_single_report(self):
9898
self.assertTrue(path.exists(expected_file),
9999
'did not generate xml report where expected.')
100100

101+
def test_django_single_report_create_folder(self):
102+
intermediate_directory = 'report'
103+
directory = path.join(self.tmpdir, intermediate_directory)
104+
self._override_settings(
105+
TEST_OUTPUT_DIR=directory,
106+
TEST_OUTPUT_FILE_NAME='results.xml',
107+
TEST_OUTPUT_VERBOSE=0,
108+
TEST_RUNNER='xmlrunner.extra.djangotestrunner.XMLTestRunner')
109+
apps.populate(settings.INSTALLED_APPS)
110+
runner_class = get_runner(settings)
111+
runner = runner_class()
112+
suite = runner.build_suite()
113+
runner.run_suite(suite)
114+
expected_file = path.join(directory, 'results.xml')
115+
self.assertTrue(path.exists(expected_file),
116+
'did not generate xml report where expected.')
117+
101118
def test_django_multiple_reports(self):
102119
self._override_settings(
103120
TEST_OUTPUT_DIR=self.tmpdir,

xmlrunner/extra/djangotestrunner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Django docs website.
1010
"""
1111

12+
import os
1213
import xmlrunner
1314
import os.path
1415
from django.conf import settings
@@ -31,6 +32,8 @@ def run_suite(self, suite, **kwargs):
3132
verbosity=verbosity, descriptions=descriptions,
3233
failfast=self.failfast)
3334
if single_file is not None:
35+
if not os.path.exists(output_dir):
36+
os.makedirs(output_dir)
3437
file_path = os.path.join(output_dir, single_file)
3538
with open(file_path, 'wb') as xml:
3639
return xmlrunner.XMLTestRunner(

0 commit comments

Comments
 (0)