Index: build/android/pylib/local/device/local_device_instrumentation_test_run.py |
diff --git a/build/android/pylib/local/device/local_device_instrumentation_test_run.py b/build/android/pylib/local/device/local_device_instrumentation_test_run.py |
index 7bfe3f5974efed2439e332afc0cd94f7ccd968ab..c23aa5c17f351422244be69a36f0d0c5245948f4 100644 |
--- a/build/android/pylib/local/device/local_device_instrumentation_test_run.py |
+++ b/build/android/pylib/local/device/local_device_instrumentation_test_run.py |
@@ -370,22 +370,29 @@ class LocalDeviceInstrumentationTestRun( |
if any(r.GetType() not in (base_test_result.ResultType.PASS, |
base_test_result.ResultType.SKIP) |
for r in results): |
- if self._test_instance.screenshot_dir: |
- file_name = '%s-%s.png' % ( |
- test_display_name, |
- time.strftime('%Y%m%dT%H%M%S', time.localtime())) |
- screenshot_file = device.TakeScreenshot( |
- os.path.join(self._test_instance.screenshot_dir, file_name)) |
- logging.info( |
- 'Saved screenshot for %s to %s.', |
- test_display_name, screenshot_file) |
- if self._test_instance.should_save_images: |
- link = google_storage_helper.upload( |
- google_storage_helper.unique_name('screenshot', device=device), |
- screenshot_file, |
- bucket='chromium-render-tests') |
- for result in results: |
- result.SetLink('failure_screenshot', link) |
+ |
+ with contextlib_ext.Optional( |
+ tempfile_ext.NamedTemporaryDirectory(), |
+ self._test_instance.screenshot_dir is None |
+ and self._test_instance.should_save_images) as screenshot_dir: |
+ |
+ screenshot_dir = self._test_instance.screenshot_dir or screenshot_dir |
+ if screenshot_dir: |
+ file_name = '%s-%s.png' % ( |
+ test_display_name, |
+ time.strftime('%Y%m%dT%H%M%S', time.localtime())) |
+ screenshot_file = device.TakeScreenshot( |
+ os.path.join(self._test_instance.screenshot_dir, file_name)) |
+ logging.info( |
+ 'Saved screenshot for %s to %s.', |
+ test_display_name, screenshot_file) |
+ if self._test_instance.should_save_images: |
+ link = google_storage_helper.upload( |
+ google_storage_helper.unique_name('screenshot', device=device), |
+ screenshot_file, |
+ bucket='chromium-render-tests') |
+ for result in results: |
+ result.SetLink('failure_screenshot', link) |
logging.info('detected failure in %s. raw output:', test_display_name) |
for l in output: |