Repository navigation
Allow debugDefaultTargetPlatformOverride to be resetted with addTearDown #110488
Copy link
Copy link
Closed
Copy link
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsfound in release: 3.0Found to occur in 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1Found to occur in 3.1frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Activity
- addedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Aug 30, 2022 @passsy: Thanks for filing the issue. This issue is reproducible on the latest
stableandmasterchannels with provided sample code.console error logs
00:02 +0: reset debugDefaultTargetPlatformOverride with tearDown ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════ The following assertion was thrown running a test: The value of a foundation debug variable was changed by the test. When the exception was thrown, this was the stack: #0 debugAssertAllFoundationVarsUnset.<anonymous closure> (package:flutter/src/foundation/debug.dart:34:7) #1 debugAssertAllFoundationVarsUnset (package:flutter/src/foundation/debug.dart:37:4) #2 TestWidgetsFlutterBinding._verifyInvariants (package:flutter_test/src/binding.dart:888:12) #3 AutomatedTestWidgetsFlutterBinding._verifyInvariants (package:flutter_test/src/binding.dart:1335:11) #4 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:875:7) <asynchronous suspension> The test description was: reset debugDefaultTargetPlatformOverride with tearDown ════════════════════════════════════════════════════════════════════════════════════════════════════ 00:02 +0 -1: reset debugDefaultTargetPlatformOverride with tearDown [E] Test failed. See exception logs above. The test description was: reset debugDefaultTargetPlatformOverride with tearDown
flutter doctor -v
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.2.1 21D62 darwin-x64, locale en-VN) • Flutter version 3.0.5 at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f1875d570e (9 hours ago), 2022-07-13 11:24:16 -0700 • Engine revision e85ea0e79c • Dart version 2.17.6 • DevTools version 2.12.2 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-33, build-tools 31.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.3) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2020.3.3) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart [✓] IntelliJ IDEA Community Edition (version 2022.1.1) • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart [✓] VS Code (version 1.69.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.44.0 [✓] Connected device (3 available) • SM T225 (mobile) • R9JT3004VRJ • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found![✓] Flutter (Channel master, 3.1.0-0.0.pre.2572, on macOS 12.5 21G72 darwin-x64, locale en-EE) • Flutter version 3.1.0-0.0.pre.2572 on channel master at /Users/huynq/Documents/GitHub/flutter_master • Upstream repository https://github.com/flutter/flutter.git • Framework revision cfee9c8467 (25 minutes ago), 2022-08-29 21:50:23 -0400 • Engine revision 0bf86adeff • Dart version 2.19.0 (build 2.19.0-149.0.dev) • DevTools version 2.16.0 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-33, build-tools 31.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 13E113 • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2020.3.3) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart [✓] IntelliJ IDEA Community Edition (version 2022.1.1) • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart [✓] VS Code (version 1.70.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.46.0 [✓] Connected device (3 available) • SM T225 (mobile) • R9JT3004VRJ • android-arm64 • Android 12 (API 31) • macOS (desktop) • macos • darwin-x64 • macOS 12.5 21G72 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.101 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found!- addeda: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onfound in release: 3.0Found to occur in 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1Found to occur in 3.1and removedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Aug 30, 2022 - addedP3Issues that are less important to the Flutter projectIssues that are less important to the Flutter project
on Aug 30, 2022 DenisBogatirov commented
on Jun 12, 2023 on Jun 12, 2023 · Hidden as duplicateshow commentMore actions- addedteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
on Jul 8, 2023 My current workaround is a custom
addFlutterTearDownwhich only works with my customtestWidgets2method/// A special version of [addTearDown] that is executed before [testWidgets] completes. /// /// Only to be used in conjunction with [robotTest]. /// /// It is required for configurations that need to be reset before the flutter test finishes, like: /// /// - [debugDefaultTargetPlatformOverride] /// - [debugImageOverheadAllowance] /// - [debugInvertOversizedImages] /// - [debugOnPaintImage] /// - [debugNetworkImageHttpClientProvider] void addFlutterTearDown(dynamic Function() callback) { if (Invoker.current == null) { throw StateError('addFlutterTearDown() may only be called within a test.'); } final list = Zone.current[#flutter_test.teardowns] as List?; if (list == null) { throw StateError('addFlutterTearDown() may only be called within using testWidgets2'); } list.add(callback); }
import 'package:test_api/src/backend/invoker.dart'; @isTest void testWidgets2( String description, WidgetTesterCallback callback, { bool? skip, Timeout? timeout, bool semanticsEnabled = true, dynamic tags, }) { final List<dynamic Function()> flutterTearDowns = []; try { testWidgets( description, (tester) async { return runZoned( () async { try { await callback(tester); } finally { await Invoker.current!.runTearDowns(flutterTearDowns); flutterTearDowns.clear(); } }, zoneValues: { #flutter_test.teardowns: flutterTearDowns, }, ); }, skip: skip, timeout: timeout, semanticsEnabled: semanticsEnabled, tags: tags, ); } finally { flutterTearDowns.clear(); } }
So I guess P3 means 3 years later at least?
Is so counterintuitive for overriding
debugDefaultTargetPlatformOverride- added a commit that references this issue
on Sep 25, 2026 - added a commit that references this issue
on Sep 26, 2026 - added 4 commits that reference this issue
on Sep 28, 2026 This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Oct 9, 2026
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsfound in release: 3.0Found to occur in 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1Found to occur in 3.1frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
produces
I was expecting
addTearDownto be the correct solution because setting the override tonullmight not be executed at the end of the test when the test fails.In fact - without
addTearDown- all remaining tests will fail with the exception above when this test fails, because it never executesdebugDefaultTargetPlatformOverride = null;.How to fix
_verifyInvariantsshould be called after executing alladdTearDown.