Ticket #20449: 1153.diff

File 1153.diff, 1.2 KB (added by tadeck, 11 years ago)

DIFF for ticket #20449, from pull request no. 1153 (https://github.com/django/django/pull/1153)

  • tests/test_runner/test_discover_runner.py

    diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py
    index 3dc364b..030a0bc 100644
    a b  
     1from contextlib import contextmanager
     2import os
     3
    14from django.test import TestCase
    25from django.test.runner import DiscoverRunner
    36
    def test_pattern(self):  
    6164        self.assertEqual(count, 1)
    6265
    6366    def test_file_path(self):
    64         count = DiscoverRunner().build_suite(
    65             ["test_discovery_sample/"],
    66         ).countTestCases()
     67        @contextmanager
     68        def change_cwd_to_tests():
     69            """Change CWD to tests directory (one level up from this file)"""
     70            current_dir = os.path.abspath(os.path.dirname(__file__))
     71            tests_dir = os.path.join(current_dir, '..')
     72            old_cwd = os.getcwd()
     73            os.chdir(tests_dir)
     74            yield
     75            os.chdir(old_cwd)
     76
     77        with change_cwd_to_tests():
     78            count = DiscoverRunner().build_suite(
     79                ["test_discovery_sample/"],
     80            ).countTestCases()
    6781
    6882        self.assertEqual(count, 4)
Back to Top