Skip to content

Commit b10dcd7

Browse files
committed
fix: ensure pact dir exists
Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent b4d6c39 commit b10dcd7

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/pact/message_pact.py

Lines changed: 7 additions & 1 deletion
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

@@ -176,16 +177,21 @@ def write_to_pact_file(self):
176177
177178
:rtype: int
178179
"""
180+
pact_dir = Path(self.pact_dir).resolve()
179181
command = [
180182
MESSAGE_PATH,
181183
"update",
182184
json.dumps(self._messages[0]),
183-
"--pact-dir", self.pact_dir,
185+
"--pact-dir", str(pact_dir),
184186
f"--pact-specification-version={self.version}",
185187
"--consumer", f"{self.consumer.name}",
186188
"--provider", f"{self.provider.name}",
187189
]
188190

191+
if not pact_dir.exists():
192+
pact_dir.mkdir(parents=True)
193+
elif not pact_dir.is_dir():
194+
raise NotADirectoryError(f"{pact_dir} is not a directory")
189195
self._message_process = Popen(command)
190196
self._message_process.wait()
191197

tests/test_message_pact.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import json
3+
from pathlib import Path
34

45
from mock import patch
56
from unittest import TestCase
@@ -242,7 +243,7 @@ def setUp(self):
242243

243244
def test_call_pact_message_to_generate_pact_file(self):
244245
target = MessagePact(
245-
self.consumer, self.provider, pact_dir='/pacts',
246+
self.consumer, self.provider, pact_dir='pacts',
246247
version='3.0.0', file_write_mode='merge', publish_to_broker=True)
247248

248249
(target
@@ -260,7 +261,7 @@ def test_call_pact_message_to_generate_pact_file(self):
260261
self.mock_Popen.assert_called_once_with([
261262
MESSAGE_PATH, 'update',
262263
json.dumps(target._messages[0]),
263-
'--pact-dir', '/pacts',
264+
'--pact-dir', str(Path("pacts").resolve()),
264265
'--pact-specification-version=3.0.0',
265266
'--consumer', 'TestConsumer',
266267
'--provider', 'TestProvider',

0 commit comments

Comments
 (0)