Skip to content

Commit 0f6b594

Browse files
committed
fix: ensure pact dir exists
Signed-off-by: JP-Ellis <[email protected]>
1 parent 10ac966 commit 0f6b594

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/pact/message_pact.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import json
55
import os
6+
from pathlib import Path
67
from subprocess import Popen
78
import warnings
89

@@ -97,7 +98,7 @@ def __init__(
9798

9899
self.consumer = consumer
99100
self.file_write_mode = file_write_mode
100-
self.pact_dir = pact_dir or os.getcwd()
101+
self.pact_dir = Path(pact_dir or os.getcwd()).resolve()
101102
self.provider = provider
102103
self.publish_to_broker = publish_to_broker
103104
self.version = version
@@ -176,11 +177,16 @@ def write_to_pact_file(self):
176177
177178
:rtype: int
178179
"""
180+
if not self.pact_dir.exists():
181+
self.pact_dir.mkdir(parents=True)
182+
elif not self.pact_dir.is_dir():
183+
raise NotADirectoryError(f"{self.pact_dir} is not a directory")
184+
179185
command = [
180186
MESSAGE_PATH,
181187
"update",
182188
json.dumps(self._messages[0]),
183-
"--pact-dir", self.pact_dir,
189+
"--pact-dir", str(self.pact_dir),
184190
f"--pact-specification-version={self.version}",
185191
"--consumer", f"{self.consumer.name}",
186192
"--provider", f"{self.provider.name}",

0 commit comments

Comments
 (0)