diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index e26cb36..00780f9 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -2431,15 +2431,25 @@ function drupal_get_bootstrap_phase() {
  *   The instance of the Container used to set up and maintain object
  *   instances.
  */
-function drupal_container(Container $reset = NULL) {
+function drupal_container($env = '', Container $reset = NULL, $reset_env = FALSE) {
   // We do not use drupal_static() here because we do not have a mechanism by
   // which to reinitialize the stored objects, so a drupal_static_reset() call
   // would leave Drupal in a nonfunctional state.
-  static $container = NULL;
+  static $containers = array();
+  if (empty($env)) {
+    // If a testing container exists, then we are in the testing environment and
+    // should use the testing container.
+    $env = isset($containers['testing']) ? 'testing' : 'prod';
+  }
+  elseif ($reset_env) {
+    unset($containers[$env]);
+    return;
+  }
+
   if (isset($reset)) {
-    $container = $reset;
+    $containers[$env] = $reset;
   }
-  elseif (!isset($container)) {
+  elseif (!isset($containers[$env])) {
     // Return a ContainerBuilder instance with the bare essentials needed for any
     // full bootstrap regardless of whether there will be a DrupalKernel involved.
     // This will get merged with the full Kernel-built Container on normal page
@@ -2461,8 +2471,10 @@ function drupal_container(Container $reset = NULL) {
     // Register configuration object factory.
     $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory')
       ->addArgument(new Reference('config.storage'));
+
+    $containers[$env] = $container;
   }
-  return $container;
+  return $containers[$env];
 }
 
 /**
@@ -2644,7 +2656,7 @@ function language($type, $reset = FALSE) {
 
   // Reset the language manager's cache and our own.
   if ($reset) {
-    if (drupal_container()->has('language_manager')) {
+    if (drupal_container()->has('language_manager') && drupal_container()->isScopeActive('language_manager')) {
       drupal_container()->get('language_manager')->reset($type);
     }
     if (!isset($type)) {
diff --git a/core/includes/path.inc b/core/includes/path.inc
index 36556a0..382fc03 100644
--- a/core/includes/path.inc
+++ b/core/includes/path.inc
@@ -370,10 +370,11 @@ function current_path() {
   // @todo Remove the check for whether the request service exists and the
   // fallback code below, once the path alias logic has been figured out in
   // http://drupal.org/node/1269742.
-  if (drupal_container()->has('request')) {
-    return drupal_container()->get('request')->attributes->get('system_path');
+  if (drupal_container()->has('request') && $path = drupal_container()->get('request')->attributes->get('system_path')) {
+    return $path;
   }
-  // If we are outside the request scope, fall back to using the path stored in
+  // If we are outside the request scope, or the system_path attribute has not
+  // yet been set on the request, fall back to using the path stored in
   // _current_path().
   return _current_path();
 }
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 869d4ee..35c7aa1 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -66,7 +66,7 @@ class DrupalKernel extends Kernel {
     //   http://drupal.org/node/1668892.
     $this->container = $this->buildContainer();
     $this->container->set('kernel', $this);
-    drupal_container($this->container);
+    drupal_container($this->environment, $this->container);
   }
 
   /**
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index f58e1de..835e2e6 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -778,7 +778,7 @@ abstract class TestBase {
     $conf = $this->originalConf;
 
     // Restore original statics and globals.
-    drupal_container($this->originalContainer);
+    drupal_container('prod', $this->originalContainer);
     $language_interface = $this->originalLanguage;
     $GLOBALS['config_directory_name'] = $this->originalConfigDirectory;
 
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index bb2aef8..d7a2a9d 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\simpletest;
 
+use Drupal\Core\DrupalKernel;
 use Drupal\Core\Database\Database;
 use Drupal\Core\Database\ConnectionNotDefinedException;
 use PDO;
@@ -682,6 +683,10 @@ abstract class WebTestBase extends TestBase {
     variable_set('mail_system', array('default-system' => 'Drupal\Core\Mail\VariableLog'));
 
     drupal_set_time_limit($this->timeLimit);
+
+    $kernel = new DrupalKernel('testing', TRUE);
+    $kernel->boot();
+
     $this->setup = TRUE;
   }
 
@@ -800,6 +805,8 @@ abstract class WebTestBase extends TestBase {
     // Rebuild caches.
     $this->refreshVariables();
 
+    // Remove the testing container.
+    drupal_container('testing', NULL, TRUE);
     // Close the CURL handler.
     $this->curlClose();
   }
