summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2014-11-19 14:08:57 -0700
committerCarl Meyer <carl@oddbird.net>2014-11-26 17:36:04 -0700
commit6f65bd1cf08c7dff9581d9033a6d534f3202eb27 (patch)
tree97aa45dc76fe926baf0cddc359fc8eecb7adeec3
parent5f79da581440dba6275f70e8a6ef440a32dbb895 (diff)
[1.7.x] Fixed #23872 -- Removed sensitivity of migrations tests to CWD.
Backport of 47b7f601eeb93bd7a91f87b77da658212f2f2314 from master.
-rw-r--r--tests/migrations/test_base.py6
-rw-r--r--tests/migrations/test_commands.py28
2 files changed, 19 insertions, 15 deletions
diff --git a/tests/migrations/test_base.py b/tests/migrations/test_base.py
index 839929d087..2bc083c7da 100644
--- a/tests/migrations/test_base.py
+++ b/tests/migrations/test_base.py
@@ -1,5 +1,8 @@
-from django.test import TransactionTestCase
+import os
+
from django.db import connection
+from django.test import TransactionTestCase
+from django.utils._os import upath
class MigrationTestBase(TransactionTestCase):
@@ -8,6 +11,7 @@ class MigrationTestBase(TransactionTestCase):
"""
available_apps = ["migrations"]
+ test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
def get_table_description(self, table):
with connection.cursor() as cursor:
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index a889ec8037..ef6f71ac94 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -11,7 +11,6 @@ from django.core.management import call_command, CommandError
from django.db.migrations import questioner
from django.test import override_settings, override_system_checks
from django.utils import six
-from django.utils._os import upath
from django.utils.encoding import force_text
from .models import UnicodeModel, UnserializableModel
@@ -153,8 +152,6 @@ class MakeMigrationsTests(MigrationTestBase):
def setUp(self):
MakeMigrationsTests.creation_counter += 1
- self._cwd = os.getcwd()
- self.test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
self.migration_dir = os.path.join(self.test_dir, 'migrations_%d' % self.creation_counter)
self.migration_pkg = "migrations.migrations_%d" % self.creation_counter
self._old_models = apps.app_configs['migrations'].models.copy()
@@ -164,19 +161,21 @@ class MakeMigrationsTests(MigrationTestBase):
apps.all_models['migrations'] = self._old_models
apps.clear_cache()
+ _cwd = os.getcwd()
os.chdir(self.test_dir)
try:
- self._rmrf(self.migration_dir)
- except OSError:
- pass
-
- try:
- self._rmrf(os.path.join(self.test_dir,
- "test_migrations_path_doesnt_exist"))
- except OSError:
- pass
+ try:
+ self._rmrf(self.migration_dir)
+ except OSError:
+ pass
- os.chdir(self._cwd)
+ try:
+ self._rmrf(os.path.join(self.test_dir,
+ "test_migrations_path_doesnt_exist"))
+ except OSError:
+ pass
+ finally:
+ os.chdir(_cwd)
def _rmrf(self, dname):
if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
@@ -553,7 +552,8 @@ class SquashMigrationsTest(MigrationTestBase):
Tests running the squashmigrations command.
"""
- path = "migrations/test_migrations/0001_squashed_0002_second.py"
+ path = "test_migrations/0001_squashed_0002_second.py"
+ path = os.path.join(MigrationTestBase.test_dir, path)
def tearDown(self):
if os.path.exists(self.path):