Skip to content

Commit 048b376

Browse files
committed
multiple index tests: correct handling of Whoosh teardown
We can't remove the Whoosh directory per-test - only after every test has run…
1 parent 21bf53b commit 048b376

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tests/multipleindex/tests.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import shutil
23
from django.conf import settings
34
from django.test import TestCase
@@ -8,6 +9,15 @@
89
from multipleindex.search_indexes import FooIndex
910
from multipleindex.models import Foo, Bar
1011

12+
def tearDownModule():
13+
# Because Whoosh doesn't clean up its mess.
14+
for name, opts in settings.HAYSTACK_CONNECTIONS.items():
15+
if "WhooshEngine" not in opts['ENGINE']:
16+
continue
17+
p = opts['PATH']
18+
if os.path.exists(p):
19+
shutil.rmtree(p)
20+
1121

1222
class MultipleIndexTestCase(TestCase):
1323
def setUp(self):
@@ -46,8 +56,7 @@ def setUp(self):
4656
def tearDown(self):
4757
self.fi.clear()
4858
self.bi.clear()
49-
# Because Whoosh doesn't clean up its mess.
50-
shutil.rmtree(settings.HAYSTACK_CONNECTIONS['whoosh']['PATH'])
59+
5160
super(MultipleIndexTestCase, self).setUp()
5261

5362
def test_index_update_object_using(self):

0 commit comments

Comments
 (0)