Skip to content

Commit 786359f

Browse files
committed
Handle nullable screenshot directory
Signed-off-by: sschulz92 <[email protected]>
1 parent efc1d46 commit 786359f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

getgauge/registry.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ def _get_step_value(step_text):
228228

229229

230230
def _take_screenshot():
231-
temp_file = _uniqe_screenshot_file()
231+
temp_file = _unique_screenshot_file()
232+
if temp_file is None:
233+
return
232234
try:
233235
call(['gauge_screenshot', temp_file])
234236
return os.path.basename(temp_file)
@@ -261,11 +263,12 @@ def capture():
261263
@staticmethod
262264
def capture_to_file():
263265
if not registry.is_screenshot_writer:
264-
screenshot_file = _uniqe_screenshot_file()
265-
content = registry.screenshot_provider()()
266-
with open(screenshot_file, "wb") as file:
267-
file.write(content)
268-
return os.path.basename(screenshot_file)
266+
screenshot_file = _unique_screenshot_file()
267+
if screenshot_file:
268+
content = registry.screenshot_provider()()
269+
with open(screenshot_file, "wb") as file:
270+
file.write(content)
271+
return os.path.basename(screenshot_file)
269272
screenshot_file = registry.screenshot_provider()()
270273
if not os.path.isabs(screenshot_file):
271274
screenshot_file = os.path.join(_screenshots_dir(), screenshot_file)
@@ -279,8 +282,12 @@ def clear():
279282
ScreenshotsStore.__screenshots = []
280283

281284

282-
def _uniqe_screenshot_file():
283-
return os.path.join(_screenshots_dir(), "screenshot-{0}.png".format(uuid1().int))
285+
def _unique_screenshot_file():
286+
screenshot_dir = _screenshots_dir()
287+
if screenshot_dir:
288+
return os.path.join(screenshot_dir, "screenshot-{0}.png".format(uuid1().int))
289+
logger.warning("Could not create unique screenshot file as no directory is configured.")
290+
return None
284291

285292

286293
def _screenshots_dir():

0 commit comments

Comments
 (0)