facebook / screenshot-tests-for-android

Generate fast deterministic screenshots during Android instrumentation tests
http://facebook.github.io/screenshot-tests-for-android
Apache License 2.0
1.74k stars 229 forks source link

This image.close crashes #322

Closed tdrhq closed 10 months ago

tdrhq commented 10 months ago

On my version of Python/PIL it crashes with:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/arnold/.gradle/caches/jars-9/c0e3396506bdc4bbb1c7955ef2d0f623/plugin-0.15.0.jar/android_screenshot_tests/pull_screenshots.py", line 721, in <module>
  File "/home/arnold/.gradle/caches/jars-9/c0e3396506bdc4bbb1c7955ef2d0f623/plugin-0.15.0.jar/android_screenshot_tests/pull_screenshots.py", line 703, in main
  File "/home/arnold/.gradle/caches/jars-9/c0e3396506bdc4bbb1c7955ef2d0f623/plugin-0.15.0.jar/android_screenshot_tests/pull_screenshots.py", line 613, in pull_screenshots
  File "/home/arnold/.gradle/caches/jars-9/c0e3396506bdc4bbb1c7955ef2d0f623/plugin-0.15.0.jar/android_screenshot_tests/recorder.py", line 110, in record
  File "/home/arnold/.gradle/caches/jars-9/c0e3396506bdc4bbb1c7955ef2d0f623/plugin-0.15.0.jar/android_screenshot_tests/recorder.py", line 80, in _record
  File "/home/arnold/.gradle/caches/jars-9/c0e3396506bdc4bbb1c7955ef2d0f623/plugin-0.15.0.jar/android_screenshot_tests/recorder.py", line 66, in _copy
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 566, in __exit__
    self._fp.close()
    ^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/PIL/_util.py", line 19, in __getattr__
    raise self.ex
ValueError: Operation on closed image

The with block should handle the closing.

Test Plan: Before applying this change, did ./gradlew :*:publishToMavenLocal and then ran ./gradlew :sample:recordDebugAndroidTestScreenshotTests. Saw crash. Made changed. Re-ran publishToMavenLocal and the tests again, and it passes this time.

facebook-github-bot commented 10 months ago

@xiphirx has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot commented 10 months ago

@xiphirx merged this pull request in facebook/screenshot-tests-for-android@f4568d4b696fd6f5b48799dc69dbe55ff6e3e641.