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

Value error: Operation on closed image when recording/verifying screenshots #309

Closed eagskunst closed 2 years ago

eagskunst commented 2 years ago

Bug description:

Executing the record/verify tasks with the last Pillow version (currently 9.2.0) raises a ValueError. Clear/Run tasks work as expected.

Stacktrace:

Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/eagskunst/.gradle/caches/modules-2/files-2.1/com.facebook.testing.screenshot/plugin/0.15.0/63cd5b4d98fcb01532138e8323032c867a7374d4/plugin-0.15.0.jar/android_screenshot_tests/pull_screenshots.py", line 721, in <module>
  File "/Users/eagskunst/.gradle/caches/modules-2/files-2.1/com.facebook.testing.screenshot/plugin/0.15.0/63cd5b4d98fcb01532138e8323032c867a7374d4/plugin-0.15.0.jar/android_screenshot_tests/pull_screenshots.py", line 703, in main
  File "/Users/eagskunst/.gradle/caches/modules-2/files-2.1/com.facebook.testing.screenshot/plugin/0.15.0/63cd5b4d98fcb01532138e8323032c867a7374d4/plugin-0.15.0.jar/android_screenshot_tests/pull_screenshots.py", line 613, in pull_screenshots
  File "/Users/eagskunst/.gradle/caches/modules-2/files-2.1/com.facebook.testing.screenshot/plugin/0.15.0/63cd5b4d98fcb01532138e8323032c867a7374d4/plugin-0.15.0.jar/android_screenshot_tests/recorder.py", line 110, in record
  File "/Users/eagskunst/.gradle/caches/modules-2/files-2.1/com.facebook.testing.screenshot/plugin/0.15.0/63cd5b4d98fcb01532138e8323032c867a7374d4/plugin-0.15.0.jar/android_screenshot_tests/recorder.py", line 80, in _record
  File "/Users/eagskunst/.gradle/caches/modules-2/files-2.1/com.facebook.testing.screenshot/plugin/0.15.0/63cd5b4d98fcb01532138e8323032c867a7374d4/plugin-0.15.0.jar/android_screenshot_tests/recorder.py", line 68, in _copy
  File "/usr/local/lib/python3.9/site-packages/PIL/Image.py", line 554, in __exit__
    self._fp.close()
  File "/usr/local/lib/python3.9/site-packages/PIL/_util.py", line 19, in __getattr__
    raise self.ex
ValueError: Operation on closed image

Library version: 0.15.0 OS: MacOS Monterrey 12.4 Arch: arm64 Python3 version: 3.9.9

Workaround

I tested Pillow version 8.0.0 and all task are working as expected.

Possible fix

I think the line causing the problem can be safely removed since the with operator already closes after it reaches the end of the scope:

https://github.com/facebook/screenshot-tests-for-android/blob/a2eb42f47b7e7e634ca47adc7b67312573c9025c/plugin/src/py/android_screenshot_tests/recorder.py#L68

The-NoiSy-BoY commented 2 years ago

I also have faced the same issue. It is confirmed that the problem is Pillow 9.2.0 I downgraded pillow to 9.1.1 Works perfectly fine.

Library version: 0.8.0 OS: MacOS BigSur 11.6.7 Arch: Intel x86_64 Python3 version: 3.9.7

eagskunst commented 2 years ago

I also have faced the same issue. It is confirmed that the problem is Pillow 9.2.0 I downgraded pillow to 9.1.1 Works perfectly fine.

Library version: 0.8.0 OS: MacOS BigSur 11.6.7 Arch: Intel x86_64 Python3 version: 3.9.7

Thanks for the confirmation. I will close the issue since it's not a problem with the source code of the library