Index: includes/install.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.inc,v
retrieving revision 1.121
diff -u -p -r1.121 install.inc
--- includes/install.inc	4 Jan 2010 21:31:52 -0000	1.121
+++ includes/install.inc	6 Jan 2010 18:10:01 -0000
@@ -535,14 +535,12 @@ function drupal_verify_profile($install_
  *
  * @param $module_list
  *   The modules to install.
- * @param $disable_modules_installed_hook
- *   Normally just testing wants to set this to TRUE.
  * 
  * @return
  *   TRUE if installation was attempted, FALSE if one or more dependencies are
  *   missing.
  */
-function drupal_install_modules($module_list = array(), $disable_modules_installed_hook = FALSE) {
+function drupal_install_modules($module_list = array()) {
   $files = system_rebuild_module_data();
   $module_list = array_flip(array_values($module_list));
   do {
@@ -572,7 +570,7 @@ function drupal_install_modules($module_
   } while ($moved);
   asort($module_list);
   $module_list = array_keys($module_list);
-  module_enable($module_list, $disable_modules_installed_hook);
+  module_enable($module_list);
   return TRUE;
 }
 
Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.177
diff -u -p -r1.177 module.inc
--- includes/module.inc	28 Dec 2009 10:48:51 -0000	1.177
+++ includes/module.inc	6 Jan 2010 18:10:38 -0000
@@ -287,10 +287,8 @@ function module_load_all_includes($type,
  *
  * @param $module_list
  *   An array of module names.
- * @param $disable_modules_installed_hook
- *   Normally just testing wants to set this to TRUE.
  */
-function module_enable($module_list, $disable_modules_installed_hook = FALSE) {
+function module_enable($module_list) {
   $invoke_modules = array();
 
   // Try to install the enabled modules and collect which were installed.
@@ -325,7 +323,7 @@ function module_enable($module_list, $di
     drupal_get_schema(NULL, TRUE);
 
     // If any modules were newly installed, execute the hook for them.
-    if (!$disable_modules_installed_hook && !empty($modules_installed)) {
+    if (!empty($modules_installed)) {
       module_invoke_all('modules_installed', $modules_installed);
     }
   }
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.188
diff -u -p -r1.188 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	4 Jan 2010 23:08:34 -0000	1.188
+++ modules/simpletest/drupal_web_test_case.php	6 Jan 2010 18:15:53 -0000
@@ -34,6 +34,17 @@ abstract class DrupalTestCase {
   protected $timeLimit = 500;
 
   /**
+   * The instance of the currently running DrupalWebTestCase.
+   */
+  protected static $this_instance = NULL;
+
+  /**
+   * Indicate to DrupalWebTestCase::preloadRegistry() that it is safe to
+   * preload the registry of the child site with information from the parent site.
+   */
+  protected $canPreloadRegistry = FALSE;
+
+  /**
    * Current results of this test case.
    *
    * @var Array
@@ -702,6 +713,13 @@ class DrupalWebTestCase extends DrupalTe
   protected $generatedTestFiles = FALSE;
 
   /**
+   * Get the currently running DrupalWebTestCase, if any.
+   */
+  public static function currentlyRunning() {
+    return self::$this_instance;
+  }
+
+  /**
    * Constructor for DrupalWebTestCase.
    */
   function __construct($test_id = NULL) {
@@ -1131,25 +1149,34 @@ class DrupalWebTestCase extends DrupalTe
     // Reset all statics so that test is performed with a clean environment.
     drupal_static_reset();
 
+    // Register this instance as the currently running one.
+    self::$this_instance = $this;
+
     include_once DRUPAL_ROOT . '/includes/install.inc';
     drupal_install_system();
 
-    $this->preloadRegistry();
+    // It is now useful to preload the child registry site with information
+    // from the parent registry.
+    $this->canPreloadRegistry = TRUE;
 
     // Include the default profile
     variable_set('install_profile', 'standard');
     $profile_details = install_profile_info('standard', 'en');
 
     // Install the modules specified by the default profile.
-    drupal_install_modules($profile_details['dependencies'], TRUE);
+    drupal_install_modules($profile_details['dependencies']);
 
     drupal_static_reset('_node_types_build');
 
     if ($modules = func_get_args()) {
       // Install modules needed for this test.
-      drupal_install_modules($modules, TRUE);
+      drupal_install_modules($modules);
     }
 
+    // At this point, we don't want that latter calls to registry_rebuild use
+    // preloading, because it would be inefficient.
+    $this->canPreloadRegistry = FALSE;
+
     // Because the schema is static cached, we need to flush
     // it between each run. If we don't, then it will contain
     // stale data for the previous run's database prefix and all
@@ -1158,7 +1185,7 @@ class DrupalWebTestCase extends DrupalTe
 
     // Run default profile tasks.
     $install_state = array();
-    drupal_install_modules(array('standard'), TRUE);
+    drupal_install_modules(array('standard'));
 
     // Rebuild caches.
     node_types_rebuild();
@@ -1192,13 +1219,17 @@ class DrupalWebTestCase extends DrupalTe
   }
 
   /**
-   * This method is called by DrupalWebTestCase::setUp, and preloads the
+   * This method is called by _registry_rebuild(), and preloads the
    * registry from the testing site to cut down on the time it takes to
    * setup a clean environment for the current test run.
    */
-  protected function preloadRegistry() {
-    db_query('INSERT INTO {registry} SELECT * FROM ' . $this->originalPrefix . 'registry');
-    db_query('INSERT INTO {registry_file} SELECT * FROM ' . $this->originalPrefix . 'registry_file');
+  public function preloadRegistry() {
+    if ($this->canPreloadRegistry) {
+      db_delete('registry')->execute();
+      db_delete('registry_file')->execute();
+      db_query('INSERT INTO {registry} SELECT * FROM ' . $this->originalPrefix . 'registry');
+      db_query('INSERT INTO {registry_file} SELECT * FROM ' . $this->originalPrefix . 'registry_file');
+    }
   }
 
   /**
