mirror of
https://github.com/django/django.git
synced 2025-06-04 02:59:13 +00:00
Fixed #20449 - Corrected test sensitivity to current working dir.
This commit is contained in:
parent
7c56212c71
commit
022de7e139
@ -1,3 +1,6 @@
|
|||||||
|
from contextlib import contextmanager
|
||||||
|
import os
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.runner import DiscoverRunner
|
from django.test.runner import DiscoverRunner
|
||||||
|
|
||||||
@ -61,8 +64,19 @@ class DiscoverRunnerTest(TestCase):
|
|||||||
self.assertEqual(count, 1)
|
self.assertEqual(count, 1)
|
||||||
|
|
||||||
def test_file_path(self):
|
def test_file_path(self):
|
||||||
count = DiscoverRunner().build_suite(
|
@contextmanager
|
||||||
["test_discovery_sample/"],
|
def change_cwd_to_tests():
|
||||||
).countTestCases()
|
"""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)
|
self.assertEqual(count, 4)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user