diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 906a7c1..bc3e785 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -3073,15 +3073,24 @@ function ip_address() {
  * are DRUPAL_ROOT and variable_get(). Otherwise it may be called as early as
  * possible.
  *
+ * @param bool $reset
+ *   (optional) Internal use only. Whether to reset the statically cached class
+ *   loader. Used by the testing framework to prevent the class loader from the
+ *   parent site (test runner) leaking into tests.
+ *
  * @return Symfony\Component\ClassLoader\UniversalClassLoader
  *   A UniversalClassLoader class instance (or extension thereof).
  */
-function drupal_classloader() {
+function drupal_classloader($reset = FALSE) {
   // By default, use the UniversalClassLoader which is best for development,
   // as it does not break when code is moved on the file system. However, as it
   // is slow, allow to use the APC class loader in production.
   static $loader;
 
+  if ($reset) {
+    $loader = NULL;
+  }
+
   if (!isset($loader)) {
     // Include the Symfony ClassLoader for loading PSR-0-compatible classes.
     require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php';
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 6f17f57..0a8b40f 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -689,6 +689,7 @@ protected function prepareEnvironment() {
     $this->originalConf = $conf;
 
     // Backup statics and globals.
+    $this->originalClassLoader = clone drupal_classloader();
     $this->originalContainer = clone drupal_container();
     $this->originalLanguage = $language_interface;
     $this->originalConfigDirectories = $GLOBALS['config_directories'];
@@ -721,6 +722,11 @@ protected function prepareEnvironment() {
     file_prepare_directory($this->temp_files_directory, FILE_CREATE_DIRECTORY);
     $this->generatedTestFiles = FALSE;
 
+    // Unregister the classloader and register a freshly built one to ensure
+    // that registered namespaces of the test runner do not leak into the test.
+    spl_autoload_unregister(array(drupal_classloader(), 'loadClass'));
+    drupal_classloader(TRUE);
+
     // Create and set new configuration directories. The child site
     // uses drupal_valid_test_ua() to adjust the config directory paths to
     // a test-prefix-specific directory within the public files directory.
@@ -809,6 +815,7 @@ protected function tearDown() {
     $conf = $this->originalConf;
 
     // Restore original statics and globals.
+    $this->originalClassLoader->register();
     drupal_container($this->originalContainer);
     $language_interface = $this->originalLanguage;
     $GLOBALS['config_directories'] = $this->originalConfigDirectories;
