only in patch2:
unchanged:
--- a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
+++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
@@ -3,6 +3,7 @@
 namespace Drupal\Core\Extension;
 
 use Drupal\Component\FileCache\FileCacheFactory;
+use Drupal\Core\DependencyInjection\ContainerNotInitializedException;
 use Drupal\Core\DrupalKernel;
 use Drupal\Core\Extension\Discovery\RecursiveExtensionFilterIterator;
 use Drupal\Core\Site\Settings;
@@ -228,7 +229,12 @@ public function scan($type, $include_tests = NULL) {
    */
   public function setProfileDirectoriesFromSettings() {
     $this->profileDirectories = [];
-    $profile = \Drupal::installProfile();
+    try {
+      $profile = \Drupal::installProfile();
+    }
+    catch (ContainerNotInitializedException $e) {
+      $profile = NULL;
+    }
     // For SimpleTest to be able to test modules packaged together with a
     // distribution we need to include the profile of the parent site (in
     // which test runs are triggered).
