From 022de7e1393541a3693919e1427d272df89f7f46 Mon Sep 17 00:00:00 2001 From: Tomasz Jaskowski Date: Sun, 19 May 2013 23:58:06 -0400 Subject: [PATCH] Fixed #20449 - Corrected test sensitivity to current working dir. --- tests/test_runner/test_discover_runner.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py index 3dc364b351..030a0bc40a 100644 --- a/tests/test_runner/test_discover_runner.py +++ b/tests/test_runner/test_discover_runner.py @@ -1,3 +1,6 @@ +from contextlib import contextmanager +import os + from django.test import TestCase from django.test.runner import DiscoverRunner @@ -61,8 +64,19 @@ class DiscoverRunnerTest(TestCase): self.assertEqual(count, 1) def test_file_path(self): - count = DiscoverRunner().build_suite( - ["test_discovery_sample/"], - ).countTestCases() + @contextmanager + def change_cwd_to_tests(): + """Change CWD to tests directory (one level up from this file)""" + current_dir = os.path.abspath(os.path.dirname(__file__)) + tests_dir = os.path.join(current_dir, '..') + old_cwd = os.getcwd() + os.chdir(tests_dir) + yield + os.chdir(old_cwd) + + with change_cwd_to_tests(): + count = DiscoverRunner().build_suite( + ["test_discovery_sample/"], + ).countTestCases() self.assertEqual(count, 4)