diff --git modules/simpletest/drupal_web_test_case.php modules/simpletest/drupal_web_test_case.php
index 7f8e8eb..66aa0d2 100644
--- modules/simpletest/drupal_web_test_case.php
+++ modules/simpletest/drupal_web_test_case.php
@@ -121,10 +121,19 @@ abstract class DrupalTestCase {
       'file' => $caller['file'],
     );
 
-    // Store assertion for display after the test has completed.
-    db_insert('simpletest')
-      ->fields($assertion)
-      ->execute();
+    // Because our $db_prefix is set to non-testing database, we must make
+    // sure to catch any exception and set it back to the testing database
+    // before continuing exception handling.
+    try {
+      // Store assertion for display after the test has completed.
+      db_insert('simpletest')
+        ->fields($assertion)
+        ->execute();
+    }
+    catch(Exception $e) {
+      $db_prefix = $current_db_prefix;
+      throw($e);
+    }
 
     // Return to testing prefix.
     $db_prefix = $current_db_prefix;
