diff --git a/setup/setup.py b/setup/setup.py index 71c27e89..47a59dd8 100644 --- a/setup/setup.py +++ b/setup/setup.py @@ -67,6 +67,7 @@ 'excludes': [ 'numpy', 'test', # CPython test data + 'PIL', ] }}, ) diff --git a/src/crystal/tests/util/screenshots.py b/src/crystal/tests/util/screenshots.py index 377d64dc..3306aa27 100644 --- a/src/crystal/tests/util/screenshots.py +++ b/src/crystal/tests/util/screenshots.py @@ -1,6 +1,5 @@ from contextlib import contextmanager import os -import pyscreeze import sys from typing import Iterator @@ -13,11 +12,16 @@ def screenshot_if_raises() -> Iterator[None]: # Take screenshot if screenshots directory path defined screenshots_dirpath = os.environ.get('CRYSTAL_SCREENSHOTS_DIRPATH') if screenshots_dirpath is not None: - os.makedirs(screenshots_dirpath, exist_ok=True) - - screenshot_filename = os.environ.get('CRYSTAL_SCREENSHOT_ID', 'screenshot') + '.png' - screenshot_filepath = os.path.join(screenshots_dirpath, screenshot_filename) - print('*** Saving screenshot to: ' + os.path.abspath(screenshot_filepath), file=sys.stderr) - pyscreeze.screenshot(screenshot_filepath) + try: + import pyscreeze + except ImportError: # probably PIL missing + print('*** Unable to save screenshot because pyscreeze not available. Probably PIL is missing.', file=sys.stderr) + else: + os.makedirs(screenshots_dirpath, exist_ok=True) + + screenshot_filename = os.environ.get('CRYSTAL_SCREENSHOT_ID', 'screenshot') + '.png' + screenshot_filepath = os.path.join(screenshots_dirpath, screenshot_filename) + print('*** Saving screenshot to: ' + os.path.abspath(screenshot_filepath), file=sys.stderr) + pyscreeze.screenshot(screenshot_filepath) raise \ No newline at end of file