Skip to content

Commit ee13461

Browse files
committed
refactor based on feedback from @nprizal
1 parent 0b54e45 commit ee13461

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

src/buildkite_test_collector/pytest_plugin/buildkite_plugin.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,16 @@ def finalize_test(self, nodeid):
113113

114114
def save_payload_as_json(self, path, merge=False):
115115
"""Save payload into a json file, merging with existing data if merge is True"""
116-
lock = FileLock(f"{path}.lock")
117-
with lock:
118-
data = list(self.payload.as_json()["data"])
119-
if merge and os.path.exists(path):
120-
try:
116+
data = list(self.payload.as_json()["data"])
117+
118+
if merge:
119+
lock = FileLock(f"{path}.lock")
120+
with lock:
121+
if os.path.exists(path):
121122
with open(path, "r", encoding="utf-8") as f:
122123
existing_data = json.load(f)
123-
except json.JSONDecodeError:
124-
existing_data = []
125-
# Merge existing data with current payload
126-
merged_data = existing_data + data
127-
else:
128-
# If file does not exist or merge is False, use current payload
129-
merged_data = data
130-
131-
with open(path, "w", encoding="utf-8") as f:
132-
json.dump(merged_data, f)
124+
# Merge existing data with current payload
125+
data = existing_data + data
126+
127+
with open(path, "w", encoding="utf-8") as f:
128+
json.dump(data, f)

0 commit comments

Comments
 (0)