Repository navigation
Allow target platform override teardown in widget tests - #186604
mvincentong wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the test binding logic to allow debugDefaultTargetPlatformOverride to be reset within addTearDown callbacks. It updates debugAssertAllFoundationVarsUnset to support an expected value for the platform override and introduces verifyInvariantsAfterTestTearDown to defer invariant checks until after user tear-downs are complete. A new test case is added to verify this behavior. I have no feedback to provide.
|
Thanks for taking a look. But I don't think this is the correct way. The fundamental problem is that |
|
Thanks, that makes sense. I updated the PR in 114c487 to follow that direction: I also broadened the regression to cover another foundation debug variable ( Verification:
|
|
Clarified this in e2cc32e: Local verification:
The targeted |
|
Follow-up: I was able to rerun the focused tests with |
e2cc32e to
7604d01
Compare
|
Rebased onto current master at |
|
Thank you for your work on this PR and for helping identify the issue. When reviewing the implementation, I found that completely and correctly handling this behavior required a substantially more complex approach across the test binding lifecycle. The solution ultimately took quite a bit of refactoring and debugging to land cleanly, so I ended up rewriting the fix, which has now been merged in #193476. Because the underlying problem is now resolved on master, I am going to close this PR. Thanks again for your time and contribution here! |
Issue: Fixes #110488.
testWidgetsused to verify Flutter test invariants before package:test executed per-testaddTearDowncallbacks. That made cleanup such asaddTearDown(() => debugDefaultTargetPlatformOverride = null)fail even though it is the safer cleanup pattern when the test body can fail before manual cleanup runs. The same ordering problem applies to other Flutter debug invariants, not just the target platform override.Fix: Defer the full Flutter invariant verification for
testWidgetsuntil after useraddTearDowncallbacks have run, but beforepostTestresets binding state. Directbinding.runTestcallers keep the existing immediate invariant verification unless they explicitly opt into the deferred hook.Tests:
./bin/flutter test packages/flutter_test/test/bindings_invariants_test.dart./bin/flutter test packages/flutter_test/test/widget_tester_test.dart./bin/flutter test packages/flutter_test/test/event_simulation_test.dart --plain-name "debugKeyEventSimulatorTransitModeOverride overrides default transit mode"./bin/flutter analyze packages/flutter/lib/src/foundation/debug.dart packages/flutter_test/lib/src/binding.dart packages/flutter_test/lib/src/widget_tester.dart packages/flutter_test/test/bindings_invariants_test.dart./bin/dart format --output=none --set-exit-if-changed packages/flutter/lib/src/foundation/debug.dart packages/flutter_test/lib/src/binding.dart packages/flutter_test/lib/src/widget_tester.dart packages/flutter_test/test/bindings_invariants_test.dartgit diff --checkRisk: This is limited to flutter_test binding cleanup. The invariant checks still run before
postTest; tests that leave debug state dirty after theiraddTearDowncallbacks still fail.