Ticket #20449: 1153.patch

File 1153.patch, 1.5 KB (added by tadeck, 11 years ago)

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

  • tests/test_runner/test_discover_runner.py

    From 8e6e3873cafa57f81df0efd82a10088cb60da770 Mon Sep 17 00:00:00 2001
    From: Tomasz Jaskowski <tadeck@gmail.com>
    Date: Sun, 19 May 2013 12:53:58 +0200
    Subject: [PATCH] fix for #20449 by altering CWD for one of the tests
    
    ---
     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 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