From f37817c34abe3d3f63ac7c19f808e005e19ceb29 Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Thu, 23 Apr 2015 19:25:27 +0200 Subject: [PATCH] SchemaTests: delete migration files in tearDownClass method Avoid leaving migration files if the method test_migration fails or tests are interrupted. Related to #103 --- tests/django_hstore_tests/tests.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/django_hstore_tests/tests.py b/tests/django_hstore_tests/tests.py index 318cadf..3432916 100755 --- a/tests/django_hstore_tests/tests.py +++ b/tests/django_hstore_tests/tests.py @@ -1189,6 +1189,16 @@ def test_str(self): class SchemaTests(TestCase): if DJANGO_VERSION[:2] >= (1, 6): + @classmethod + def tearDownClass(cls): + # delete migration files + migration_path = '{0}/{1}'.format(os.path.dirname(__file__), 'migrations') + import shutil + try: + shutil.rmtree(migration_path) + except OSError: + pass + def _login_as_admin(self): # create admin user admin = User.objects.create(username='admin', password='tester', is_staff=True, is_superuser=True, is_active=True) @@ -1556,9 +1566,6 @@ class Migration(migrations.Migration): # stop capturing print statements sys.stdout = sys.__stdout__ self.assertIn('Applying django_hstore_tests.0002_issue_103... OK', output.getvalue()) - # delete migration files - import shutil - shutil.rmtree(path) else: def test_improperly_configured(self): with self.assertRaises(ImproperlyConfigured):