Skip to content

Commit b5c0174

Browse files
aaronsteersCopilot
andauthored
Update airbyte_cdk/test/standard_tests/models/scenario.py
Co-authored-by: Copilot <[email protected]>
1 parent dc788fa commit b5c0174

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

airbyte_cdk/test/standard_tests/models/scenario.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,13 @@ def __str__(self) -> str:
9494
def with_temp_config_file(self) -> Generator[Path, None, None]:
9595
"""Yield a temporary JSON file path containing the config dict and delete it on exit."""
9696
config = self.get_config_dict(empty_if_missing=True)
97-
_, path_str = tempfile.mkstemp(prefix="config-", suffix=".json", text=True)
98-
path = Path(path_str)
99-
try:
100-
path.write_text(json.dumps(config))
97+
with tempfile.NamedTemporaryFile(prefix="config-", suffix=".json", mode="w", delete=False) as temp_file:
98+
temp_file.write(json.dumps(config))
99+
temp_file.flush()
101100
# Allow the file to be read by other processes
102-
path.chmod(path.stat().st_mode | 0o444)
103-
yield path
104-
finally:
105-
# attempt cleanup, ignore errors
106-
with suppress(OSError):
107-
path.unlink()
101+
temp_path = Path(temp_file.name)
102+
temp_path.chmod(temp_path.stat().st_mode | 0o444)
103+
yield temp_path
104+
# attempt cleanup, ignore errors
105+
with suppress(OSError):
106+
temp_path.unlink()

0 commit comments

Comments
 (0)