← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:run-isolated-test-without-layer into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:run-isolated-test-without-layer into launchpad:master.

Commit message:
Make RunIsolatedTest work without a layer

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/388953

Some tests use RunIsolatedTest without a layer.  This shouldn't crash the test runner.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:run-isolated-test-without-layer into launchpad:master.
diff --git a/lib/lp/testing/__init__.py b/lib/lp/testing/__init__.py
index a75ae5c..8b43a1c 100644
--- a/lib/lp/testing/__init__.py
+++ b/lib/lp/testing/__init__.py
@@ -1280,8 +1280,9 @@ class RunIsolatedTest(testtools.RunTest):
             protocol.readFrom(fdread)
             fdread.close()
             os.waitpid(pid, 0)
-            if issubclass(self.case.layer, DatabaseLayer):
-                self.case.layer.force_dirty_database()
+            layer = getattr(self.case, 'layer', None)
+            if layer is not None and issubclass(layer, DatabaseLayer):
+                layer.force_dirty_database()
 
 
 class EventRecorder: