open files using with statement
This commit is contained in:
parent
99a12b2b22
commit
49668a4f4f
|
@ -35,9 +35,9 @@ def save_json(req_json):
|
|||
if not os.path.isdir(TMP_SNAPSHOTS):
|
||||
os.system('mkdir -p {}'.format(TMP_SNAPSHOTS))
|
||||
|
||||
snapshot_file = open(path_name, 'w')
|
||||
with open(path_name, 'w') as snapshot_file:
|
||||
snapshot_file.write(json.dumps(req_json))
|
||||
snapshot_file.close()
|
||||
|
||||
return path_name
|
||||
|
||||
|
||||
|
|
|
@ -492,9 +492,9 @@ def test_save_snapshot_in_file():
|
|||
snapshot = {'software': '', 'version': '', 'uuid': ''}
|
||||
if files:
|
||||
path_snapshot = os.path.join(TMP_SNAPSHOTS, files[0])
|
||||
file_snapshot = open(path_snapshot)
|
||||
with open(path_snapshot) as file_snapshot:
|
||||
snapshot = json.loads(file_snapshot.read())
|
||||
file_snapshot.close()
|
||||
|
||||
os.remove(path_snapshot)
|
||||
|
||||
assert snapshot['software'] == snapshot_no_hid['software']
|
||||
|
@ -515,9 +515,9 @@ def test_backup_snapshot_with_errors(user: UserClient):
|
|||
files = [x for x in os.listdir(TMP_SNAPSHOTS) if uuid in x]
|
||||
if files:
|
||||
path_snapshot = os.path.join(TMP_SNAPSHOTS, files[0])
|
||||
file_snapshot = open(path_snapshot)
|
||||
with open(path_snapshot) as file_snapshot:
|
||||
snapshot = json.loads(file_snapshot.read())
|
||||
file_snapshot.close()
|
||||
|
||||
os.remove(path_snapshot)
|
||||
|
||||
assert snapshot['software'] == snapshot_no_hid['software']
|
||||
|
|
Reference in a new issue