diff --git a/src/rai_core/rai/messages/artifacts.py b/src/rai_core/rai/messages/artifacts.py index 870174344..0dc10d9f5 100644 --- a/src/rai_core/rai/messages/artifacts.py +++ b/src/rai_core/rai/messages/artifacts.py @@ -28,6 +28,7 @@ def store_artifacts( # TODO(boczekbartek): refactor path = Path(db_path) if not path.is_file(): + path.parent.mkdir(parents=True, exist_ok=True) artifact_database: dict = {} with path.open("wb") as file: pickle.dump(artifact_database, file) diff --git a/tests/messages/test_artifacts_db_path.py b/tests/messages/test_artifacts_db_path.py index 83efc1d77..9792465c1 100644 --- a/tests/messages/test_artifacts_db_path.py +++ b/tests/messages/test_artifacts_db_path.py @@ -27,8 +27,7 @@ def test_store_artifacts_honors_db_path(tmp_path: Path): assert get_stored_artifacts("missing", db_path=str(db)) == [] -def test_store_artifacts_creates_file_at_path(tmp_path: Path): - db = tmp_path / "nested" / "db.pkl" - db.parent.mkdir(parents=True) +def test_store_artifacts_creates_nested_path(tmp_path: Path): + db = tmp_path / "nested" / "dir" / "db.pkl" store_artifacts("x", [1], db_path=str(db)) assert get_stored_artifacts("x", db_path=str(db)) == [1]