Skip to content

Running flutter test --update-goldens with an integration test causes FileSystemException #143299

Closed

Description

@tbuczkowski

Steps to reproduce

  1. Add the integration_test package to the project and create an integration test.
  2. Add an expectLater with matchesGoldenFile('some_file.png') somewhere in the test.
  3. Run flutter test <path to the test> --update-goldens on an Android Emulator (I didn't test on iOS)
  4. The integration test will run normally but will throw FileSystemException after finishing and produce no screenshots.

Expected results

Images for the golden tests should be created and the test run should not throw any exceptions.

If I run the same test but as a widget test instead of integration test, the images get created correctly, but then there's the limitation of not being able to access any native APIs in the test, since it's not being run on a device/emulator.

Since matchesGoldenFile docs don't mention anything about it not working in an integration test environment, I'd presume it should work the same way in widget and integration tests.

Actual results

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following FileSystemException was thrown while running async test code:
Creation failed, path = '/Users' (OS Error: Read-only file system, errno = 30)

When the exception was thrown, this was the stack:
#0      _checkForErrorResponse (dart:io/common.dart:55:9)
#1      _Directory.create.<anonymous closure> (dart:io/directory_impl.dart:114:9)
<asynchronous suspension>
#7      _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
<asynchronous suspension>
#8      _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
<asynchronous suspension>
#9      _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
<asynchronous suspension>
#10     _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
<asynchronous suspension>
#11     _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
<asynchronous suspension>
#12     _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
<asynchronous suspension>
#13     _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
<asynchronous suspension>
#14     LocalFileComparator.update (package:flutter_test/src/_goldens_io.dart:109:5)
<asynchronous suspension>
#15     MatchesGoldenFile.matchAsync.<anonymous closure> (package:flutter_test/src/_matchers_io.dart:114:11)
<asynchronous suspension>
#16     LiveTestWidgetsFlutterBinding.runAsync (package:flutter_test/src/binding.dart:1990:14)
<asynchronous suspension>
#17     _expect.<anonymous closure> (package:matcher/src/expect/expect.dart:123:26)
<asynchronous suspension>
<asynchronous suspension>
#19     expectLater.<anonymous closure> (package:flutter_test/src/widget_tester.dart:496:24)
<asynchronous suspension>
#20     main.setBudgetAndQuantityAndGoToCheckout (file:///Users/<username>/<path to the project>/integration_test/guest_blind_order_checkout_flow_test.dart:233:5)
<asynchronous suspension>
#21     main.<anonymous closure> (file:///Users/<username>/<path to the project>/integration_test/guest_blind_order_checkout_flow_test.dart:349:5)
<asynchronous suspension>
#22     testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:168:15)
<asynchronous suspension>
#23     TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1013:5)
<asynchronous suspension>
<asynchronous suspension>
(elided 7 frames from dart:async and package:stack_trace)
════════════════════════════════════════════════════════════════════════════════════════════════════

Test failed. See exception logs above.

Code sample

Code sample Any integration test containing `matchesGoldenFile` call.

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.2.1 23C71 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.86.0)
[✓] Connected device (5 available)
[✓] Network resources

• No issues found!

Activity

  1. changed the title [-]Running `flutter test --update-goldens` in an integration test causes FileSystemException[/-] [+]Running `flutter test --update-goldens` with an integration test causes FileSystemException[/+] on Feb 12, 2024
  2. dam-ease commented on Feb 13, 2024

    @dam-ease

    Hello @tbuczkowski.
    Thanks for filing this.
    From the logs, you seem to be hitting #94197. Can you check though to confirm this is similar/related to your issue?

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 13, 2024
  4. tbuczkowski commented on Feb 13, 2024

    @tbuczkowski
    Author

    Hi @dam-ease. Yes, I think they are similar, but refer to different use cases. The issue you linked is more about manually loading some assets during integration tests and this one is about just running golden tests without explicitly accessing any files/assets. So I'm not sure if they qualify as separate issues or should be merged into one?

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 13, 2024
  6. dam-ease commented on Feb 13, 2024

    @dam-ease

    Thanks for your response @tbuczkowski.
    Could you please share a simple repo that we can run on our end to reproduce your own case?

  7. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 13, 2024
  8. tbuczkowski commented on Feb 14, 2024

    @tbuczkowski
    Author
  9. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 14, 2024
  10. dam-ease commented on Feb 15, 2024

    @dam-ease

    Thanks for your response @tbuczkowski
    Running the sample above, the test runs infinitely on my end.
    Can you share your full logs in a .txt file?

  11. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 15, 2024
  12. tbuczkowski commented on Feb 15, 2024

    @tbuczkowski
    Author

    It's just the example test from https://docs.flutter.dev/cookbook/testing/integration/introduction with the line await expectLater(fab, matchesGoldenFile('fab.png')); added. There's really nothing more to it than what I posted in the first message.

  13. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 15, 2024
  14. dam-ease commented on Feb 15, 2024

    @dam-ease

    Thanks for your response @tbuczkowski.
    I seem to have missed out on a step, I can reproduce this on the latest master and stable channels.
    Tested this on iOS and couldn't reproduce, this seems to be specific to Android.

    Logs

    flutter test /Users/damilolaalimi/Downloads/issue143299/integration_test/example_test.dart --update-goldens
    00:00 +0: ...nloads/issue143299/integration_test/example_test.dart     R00:14 +0: ...nloads/issue143299/integration_test/example_test.d   13.9s
    ✓  Built build/app/outputs/flutter-apk/app-debug.apk.
    00:16 +0: ...nloads/issue143299/integration_test/example_test.dart     I00:25 +0: ...nloads/issue143299/integration_test/example_test.d    9.0s
    00:30 +0: end-to-end test tap on the floating action button, verify counter
    ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
    The following FileSystemException was thrown while running async test code:
    Creation failed, path = '/Users' (OS Error: Read-only file system, errno = 30)
    
    When the exception was thrown, this was the stack:
    #0      _checkForErrorResponse (dart:io/common.dart:55:9)
    #1      _Directory.create.<anonymous closure> (dart:io/directory_impl.dart:114:9)
    <asynchronous suspension>
    #7      _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
    <asynchronous suspension>
    #8      _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
    <asynchronous suspension>
    #9      _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
    <asynchronous suspension>
    #10     _Directory.create.<anonymous closure>.<anonymous closure> (dart:io/directory_impl.dart:104:54)
    <asynchronous suspension>
    #11     LocalFileComparator.update (package:flutter_test/src/_goldens_io.dart:109:5)
    <asynchronous suspension>
    #12     MatchesGoldenFile.matchAsync.<anonymous closure> (package:flutter_test/src/_matchers_io.dart:114:11)
    <asynchronous suspension>
    #13     LiveTestWidgetsFlutterBinding.runAsync (package:flutter_test/src/binding.dart:1990:14)
    <asynchronous suspension>
    #14     _expect.<anonymous closure> (package:matcher/src/expect/expect.dart:123:26)
    <asynchronous suspension>
    <asynchronous suspension>
    #16     expectLater.<anonymous closure> (package:flutter_test/src/widget_tester.dart:496:24)
    <asynchronous suspension>
    #17     main.<anonymous closure>.<anonymous closure> (file:///Users/damilolaalimi/Downloads/issue143299/integration_test/example_test.dart:21:7)
    <asynchronous suspension>
    #18     testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:168:15)
    <asynchronous suspension>
    #19     TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1013:5)
    <asynchronous suspension>
    <asynchronous suspension>
    (elided 7 frames from dart:async and package:stack_trace)
    ════════════════════════════════════════════════════════════════════════════════════════════════════
    00:30 +0 -1: end-to-end test tap on the floating action button, verify counter [E]
      Test failed. See exception logs above.
      The test description was: tap on the floating action button, verify counter
      
    
    To run this test again: /Users/damilolaalimi/sdks/flutter/bin/cache/dart-sdk/bin/dart test /Users/damilolaalimi/Downloads/issue143299/integration_test/example_test.dart -p vm --plain-name 'end-to-end test tap on the floating action button, verify counter'
    00:31 +0 -1: Some tests failed.    
    

    stable, master flutter doctor -v

    [!] Flutter (Channel stable, 3.16.9, on macOS 14.2.1 23C71 darwin-arm64, locale
        en-NG)
        • Flutter version 3.16.9 on channel stable at
          /Users/damilolaalimi/sdks/flutter
        ! Warning: `dart` on your path resolves to
          /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/damilolaalimi/sdks/flutter.
          Consider adding /Users/damilolaalimi/sdks/flutter/bin to the front of your
          path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 41456452f2 (3 weeks ago), 2024-01-25 10:06:23 -0800
        • Engine revision f40e976bed
        • Dart version 3.2.6
        • DevTools version 2.28.5
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android
          Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.2)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15C500b
        • CocoaPods version 1.14.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.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
          17.0.6+0-17.0.6b802.4-9586694)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Users/damilolaalimi/Downloads/Android Studio
          Preview.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
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build
          17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.86.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] VS Code (version 1.83.1)
        • VS Code at /Users/damilolaalimi/Downloads/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] Connected device (5 available)
        • sdk gphone64 arm64 (mobile) • emulator-5554                        •
          android-arm64  • Android 14 (API 34) (emulator)
        • Damilola’s iPhone (mobile)  • 00008110-001964480AE1801E            • ios
          • iOS 17.1.1 21B91
        • iPhone 15 (mobile)          • DBCC5388-DA57-470E-8F0E-477EA0AA3C3A • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
        • macOS (desktop)             • macos                                •
          darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
        • Chrome (web)                • chrome                               •
          web-javascript • Google Chrome 121.0.6167.184
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
    
    [!] Flutter (Channel master, 3.20.0-7.0.pre.43, on macOS 14.2.1 23C71 darwin-arm64, locale en-NG)
        • Flutter version 3.20.0-7.0.pre.43 on channel master at /Users/damilolaalimi/fvm/versions/master
        ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/damilolaalimi/fvm/versions/master. Consider adding /Users/damilolaalimi/fvm/versions/master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 295eeaf100 (4 hours ago), 2024-02-13 19:58:58 -0800
        • Engine revision 3af336bfb2
        • Dart version 3.4.0 (build 3.4.0-140.0.dev)
        • DevTools version 2.33.0-dev.6
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.2)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15C500b
        • CocoaPods version 1.14.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.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 17.0.6+0-17.0.6b802.4-9586694)
    
    [!] Android Studio (version unknown)
        • Android Studio at /Users/damilolaalimi/Downloads/Android Studio Preview.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
        ✗ Unable to determine Android Studio version.
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.86.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] VS Code (version 1.83.1)
        • VS Code at /Users/damilolaalimi/Downloads/Visual Studio Code.app/Contents
        • Flutter extension version 3.78.0
    
    [✓] Connected device (6 available)
        • sdk gphone64 arm64 (mobile)     • emulator-5554                        • android-arm64  • Android 14 (API 34) (emulator)
        • Damilola’s iPhone (mobile)      • 00008110-001964480AE1801E            • ios            • iOS 17.1.1 21B91
        • iPhone 15 (mobile)              • DBCC5388-DA57-470E-8F0E-477EA0AA3C3A • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
        • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
        • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 14.2.1 23C71 darwin-arm64
        • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 121.0.6167.184
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
    

  15. 9 remaining items

  16. deborahdcarlo commented on Feb 21, 2024

    @deborahdcarlo

    I am running into same problem as @tbuczkowski. Can't golden tests be used on an integration test? I do see the images getting generated if done on a widget test, but not on integration (which is frustrating). Any solution for this problem so far?

  17. dam-ease commented on Feb 22, 2024

    @dam-ease

    There is an existing issue related to golden tests being used with integration tests #103222.
    #103222 (comment) looks like a description the root cause of this issue.

  18. added
    P2Important issues not at the top of the work list
    triaged-androidTriaged by Android platform team
    on Feb 29, 2024
  19. camsim99 commented on Jul 22, 2024

    @camsim99
    Contributor

    I ran into the read-only file system issue (Creation failed, path = '/Users' (OS Error: Read-only file system, errno = 30)), as well, and dug into this a bit because I would like to write an integration test that uses the goldens logic.

    Seems like the root cause there is that the test is trying to write the golden files (like the images) to the actual device the test is running on, and it's trying to write in a directory (intended for the host machine) that is not writable on the device. I tried using the path_provider plugin to get the directory that the application can write to (with getApplicationDocumentsDirectory), and when I modified the Flutter goldens logic to write it here, I was able to see the golden files on the device. However, this also required that I delay the end of the test because the app is automatically deleted (along with its storage) after the test runs. I need to find a way to stop the uninstall after the test run realistically, but I was just trying to see what was going on.

    Ideally, we find a way to write the golden files to the host machine instead of the device, so I'm going to start looking into this.

  20. self-assigned this
    on Jul 22, 2024
  21. matanlurey commented on Jul 22, 2024

    @matanlurey
    Contributor

    @johnmccutchan and I had a prototype, https://github.com/johnmccutchan/fgs, which did this: it's not in a state where we could land it, and probably needs additional design work and some vetting from platform folks.

    I am not sure there is a smaller workaround than what you've already discovered (i.e. making the test aware of the environment). It might be helpful to understand what you are trying to test, and also whether this arc of work will help, or not.

    Happy to chat further!

  22. removed their assignment
    on Jul 25, 2024
  23. self-assigned this
    on Dec 10, 2024
  24. github-actions commented on Feb 27, 2025

    @github-actions

    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 -v and a minimal reproduction of the issue.

  25. locked as resolved and limited conversation to collaborators on Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsf: integration_testThe flutter/packages/integration_test pluginfound in release: 3.16Found to occur in 3.16found in release: 3.20Found to occur in 3.20has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions