Merge lp:~lifeless/launchpad/test into lp:launchpad

Proposed by Robert Collins
Status: Merged
Merged at revision: 11678
Proposed branch: lp:~lifeless/launchpad/test
Merge into: lp:launchpad
Diff against target: 72 lines (+18/-0)
1 file modified
lib/canonical/testing/layers.py (+18/-0)
To merge this branch: bzr merge lp:~lifeless/launchpad/test
Reviewer Review Type Date Requested Status
Henning Eggers (community) code Approve
Review via email: mp+37571@code.launchpad.net

Description of the change

Make memcache/database/librarian layers tolerant of being torn down twice to cater to zope.testrunner layer behaviour.

To post a comment you must log in.
Revision history for this message
Henning Eggers (henninge) wrote :

Simple enough fix, thank you, but can you please rename _setup to _is_setup or _is_set_up?

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/testing/layers.py'
2--- lib/canonical/testing/layers.py 2010-10-04 06:20:04 +0000
3+++ lib/canonical/testing/layers.py 2010-10-05 08:51:00 +0000
4@@ -482,9 +482,12 @@
5 # memcached.
6 _memcached_process = None
7
8+ _is_setup = False
9+
10 @classmethod
11 @profiled
12 def setUp(cls):
13+ cls._is_setup = True
14 # Create a client
15 MemcachedLayer.client = memcache_client_factory()
16 if (BaseLayer.persist_test_services and
17@@ -531,6 +534,9 @@
18 @classmethod
19 @profiled
20 def tearDown(cls):
21+ if not cls._is_setup:
22+ return
23+ cls._is_setup = False
24 MemcachedLayer.client.disconnect_all()
25 MemcachedLayer.client = None
26 if not BaseLayer.persist_test_services:
27@@ -568,9 +574,12 @@
28 """
29 _reset_between_tests = True
30
31+ _is_setup = False
32+
33 @classmethod
34 @profiled
35 def setUp(cls):
36+ cls._is_setup = True
37 if not LibrarianLayer._reset_between_tests:
38 raise LayerInvariantError(
39 "_reset_between_tests changed before LibrarianLayer "
40@@ -584,6 +593,9 @@
41 @classmethod
42 @profiled
43 def tearDown(cls):
44+ if not cls._is_setup:
45+ return
46+ cls._is_setup = False
47 if not LibrarianLayer._reset_between_tests:
48 raise LayerInvariantError(
49 "_reset_between_tests not reset before LibrarianLayer "
50@@ -680,9 +692,12 @@
51 # Database.force_dirty_database() when you do so.
52 _reset_between_tests = True
53
54+ _is_setup = False
55+
56 @classmethod
57 @profiled
58 def setUp(cls):
59+ cls._is_setup = True
60 DatabaseLayer.force_dirty_database()
61 # Imported here to avoid circular import issues. This
62 # functionality should be migrated into this module at some
63@@ -695,6 +710,9 @@
64 @classmethod
65 @profiled
66 def tearDown(cls):
67+ if not cls._is_setup:
68+ return
69+ cls._is_setup = False
70 # Don't leave the DB lying around or it might break tests
71 # that depend on it not being there on startup, such as found
72 # in test_layers.py