=== modified file 'includes/database/mysql/database.inc'
--- includes/database/mysql/database.inc	2010-06-29 13:42:18 +0000
+++ includes/database/mysql/database.inc	2010-06-29 18:27:50 +0000
@@ -95,8 +95,9 @@ class DatabaseConnection_mysql extends D
       $this->query('INSERT INTO {sequences} (value) VALUES (:value) ON DUPLICATE KEY UPDATE value = value', array(':value' => $existing_id));
       $new_id = $this->query('INSERT INTO {sequences} () VALUES ()', array(), array('return' => Database::RETURN_INSERT_ID));
     }
-    if (!$this->shutdownRegistered) {
-      drupal_register_shutdown_function(array($this, 'nextIdDelete'));
+    // Do not run the shutdown function during testing.
+    if (!$this->shutdownRegistered && empty($GLOBALS['drupal_test_info'])) {
+      register_shutdown_function(array($this, 'nextIdDelete'));
       $shutdownRegistered = TRUE;
     }
     return $new_id;

