From c8d3f3620cd1e04bb8d7f6c68c4eba219edef3a2 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Mon, 4 Sep 2023 17:25:14 +0200 Subject: [PATCH] code review: second part for file write using ctx mgr --- tests/e2e/test_runtime.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/e2e/test_runtime.py b/tests/e2e/test_runtime.py index 1f011b4a..5e2f7059 100644 --- a/tests/e2e/test_runtime.py +++ b/tests/e2e/test_runtime.py @@ -264,9 +264,8 @@ def test_hot_reload(): assert found_rule_1_in_out data = original_data.replace('- action: "value_a"', '- action: "value_b"') - fout1 = open(rulebook, "wt") - fout1.write(data) - fout1.close() + with open(rulebook, "wt") as file: + file.write(data) start = time.time() while line := process.stdout.readline(): @@ -277,8 +276,7 @@ def test_hot_reload(): if time.time() - start > DEFAULT_CMD_TIMEOUT: process.kill() - fout2 = open(rulebook, "wt") - fout2.write(original_data) - fout2.close() + with open(rulebook, "wt") as file: + file.write(original_data) assert found_rule_2_in_out