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
|
|
| 1 | from contextlib import contextmanager |
| 2 | import os |
| 3 | |
1 | 4 | from django.test import TestCase |
2 | 5 | from django.test.runner import DiscoverRunner |
3 | 6 | |
… |
… |
def test_pattern(self):
|
61 | 64 | self.assertEqual(count, 1) |
62 | 65 | |
63 | 66 | 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() |
67 | 81 | |
68 | 82 | self.assertEqual(count, 4) |