From 1c2a957f993c4f85b0d9ed93b03e0c6480c124c2 Mon Sep 17 00:00:00 2001 From: Daniel Brummerloh Date: Wed, 13 Dec 2023 17:01:50 +0100 Subject: [PATCH] fix bug in get_latest_session_id when dir didnt exist --- pytest_abra/dir_manager.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pytest_abra/dir_manager.py b/pytest_abra/dir_manager.py index c20f03c..b5ca29e 100644 --- a/pytest_abra/dir_manager.py +++ b/pytest_abra/dir_manager.py @@ -80,7 +80,13 @@ class DirManager: @staticmethod def get_latest_session_id(output_dir: Path) -> Optional[str]: - """returns the name of the newest dir inside of output_dir""" + """returns the name of the newest dir inside of output_dir + + if output_dir does not exists or is empty, None is returned""" + + if not output_dir.is_dir(): + return None + all_dirs = [d for d in output_dir.iterdir() if d.is_dir()] if all_dirs: newest_dir: Path = max(all_dirs, key=lambda x: x.stat().st_ctime)