diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index 2bacfcebca..cb4af67839 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -81,8 +81,7 @@ namespace osu.Game.Tests.Visual protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { - if (!UseFreshStoragePerRun) - isolatedHostStorage = (parent.Get() as HeadlessGameHost)?.Storage; + isolatedHostStorage = (parent.Get() as HeadlessGameHost)?.Storage; Resources = parent.Get().Resources; @@ -149,8 +148,16 @@ namespace osu.Game.Tests.Visual } } - localStorage = - new Lazy(() => isolatedHostStorage ?? new TemporaryNativeStorage($"{GetType().Name}-{Guid.NewGuid()}")); + localStorage = new Lazy(() => + { + // When running headless, there is an opportunity to use the host storage rather than creating a second isolated one. + // This is because the host is recycled per TestScene execution in headless at an nunit level. + // Importantly, we can't use this optimisation when `UseFreshStoragePerRun` is true, as it doesn't reset per test method. + if (!UseFreshStoragePerRun && isolatedHostStorage != null) + return isolatedHostStorage; + + return new TemporaryNativeStorage($"{GetType().Name}-{Guid.NewGuid()}"); + }); } [Resolved]