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
=== modified file 'lib/canonical/testing/layers.py'
--- lib/canonical/testing/layers.py 2010-10-04 06:20:04 +0000
+++ lib/canonical/testing/layers.py 2010-10-05 08:51:00 +0000
@@ -482,9 +482,12 @@
482 # memcached.482 # memcached.
483 _memcached_process = None483 _memcached_process = None
484484
485 _is_setup = False
486
485 @classmethod487 @classmethod
486 @profiled488 @profiled
487 def setUp(cls):489 def setUp(cls):
490 cls._is_setup = True
488 # Create a client491 # Create a client
489 MemcachedLayer.client = memcache_client_factory()492 MemcachedLayer.client = memcache_client_factory()
490 if (BaseLayer.persist_test_services and493 if (BaseLayer.persist_test_services and
@@ -531,6 +534,9 @@
531 @classmethod534 @classmethod
532 @profiled535 @profiled
533 def tearDown(cls):536 def tearDown(cls):
537 if not cls._is_setup:
538 return
539 cls._is_setup = False
534 MemcachedLayer.client.disconnect_all()540 MemcachedLayer.client.disconnect_all()
535 MemcachedLayer.client = None541 MemcachedLayer.client = None
536 if not BaseLayer.persist_test_services:542 if not BaseLayer.persist_test_services:
@@ -568,9 +574,12 @@
568 """574 """
569 _reset_between_tests = True575 _reset_between_tests = True
570576
577 _is_setup = False
578
571 @classmethod579 @classmethod
572 @profiled580 @profiled
573 def setUp(cls):581 def setUp(cls):
582 cls._is_setup = True
574 if not LibrarianLayer._reset_between_tests:583 if not LibrarianLayer._reset_between_tests:
575 raise LayerInvariantError(584 raise LayerInvariantError(
576 "_reset_between_tests changed before LibrarianLayer "585 "_reset_between_tests changed before LibrarianLayer "
@@ -584,6 +593,9 @@
584 @classmethod593 @classmethod
585 @profiled594 @profiled
586 def tearDown(cls):595 def tearDown(cls):
596 if not cls._is_setup:
597 return
598 cls._is_setup = False
587 if not LibrarianLayer._reset_between_tests:599 if not LibrarianLayer._reset_between_tests:
588 raise LayerInvariantError(600 raise LayerInvariantError(
589 "_reset_between_tests not reset before LibrarianLayer "601 "_reset_between_tests not reset before LibrarianLayer "
@@ -680,9 +692,12 @@
680 # Database.force_dirty_database() when you do so.692 # Database.force_dirty_database() when you do so.
681 _reset_between_tests = True693 _reset_between_tests = True
682694
695 _is_setup = False
696
683 @classmethod697 @classmethod
684 @profiled698 @profiled
685 def setUp(cls):699 def setUp(cls):
700 cls._is_setup = True
686 DatabaseLayer.force_dirty_database()701 DatabaseLayer.force_dirty_database()
687 # Imported here to avoid circular import issues. This702 # Imported here to avoid circular import issues. This
688 # functionality should be migrated into this module at some703 # functionality should be migrated into this module at some
@@ -695,6 +710,9 @@
695 @classmethod710 @classmethod
696 @profiled711 @profiled
697 def tearDown(cls):712 def tearDown(cls):
713 if not cls._is_setup:
714 return
715 cls._is_setup = False
698 # Don't leave the DB lying around or it might break tests716 # Don't leave the DB lying around or it might break tests
699 # that depend on it not being there on startup, such as found717 # that depend on it not being there on startup, such as found
700 # in test_layers.py718 # in test_layers.py