]> Git Repo - qemu.git/commitdiff
iotests: use with-statement for open() calls
authorJohn Snow <[email protected]>
Tue, 20 Jul 2021 17:33:20 +0000 (13:33 -0400)
committerHanna Reitz <[email protected]>
Wed, 1 Sep 2021 10:57:31 +0000 (12:57 +0200)
Silences a new pylint warning. The dangers of *not* doing this are
somewhat unclear; I believe the file object gets garbage collected
eventually, but possibly the way in which it happens is
non-deterministic. Maybe this is a valid warning, but if there are
consequences of not doing it, I am not aware of them at present.

Signed-off-by: John Snow <[email protected]>
Message-Id: <20210720173336.1876937[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Hanna Reitz <[email protected]>
tests/qemu-iotests/iotests.py

index 2cf5ff965bd6e3371f591cc6e978558902730bdf..2ad7a15c8b3313842508a33e5e5e88d73d21d1ea 100644 (file)
@@ -1120,7 +1120,8 @@ def notrun(reason):
     # Each test in qemu-iotests has a number ("seq")
     seq = os.path.basename(sys.argv[0])
 
-    open('%s/%s.notrun' % (output_dir, seq), 'w').write(reason + '\n')
+    with open('%s/%s.notrun' % (output_dir, seq), 'w') as outfile:
+        outfile.write(reason + '\n')
     logger.warning("%s not run: %s", seq, reason)
     sys.exit(0)
 
@@ -1133,8 +1134,8 @@ def case_notrun(reason):
     # Each test in qemu-iotests has a number ("seq")
     seq = os.path.basename(sys.argv[0])
 
-    open('%s/%s.casenotrun' % (output_dir, seq), 'a').write(
-        '    [case not run] ' + reason + '\n')
+    with open('%s/%s.casenotrun' % (output_dir, seq), 'a') as outfile:
+        outfile.write('    [case not run] ' + reason + '\n')
 
 def _verify_image_format(supported_fmts: Sequence[str] = (),
                          unsupported_fmts: Sequence[str] = ()) -> None:
This page took 0.02914 seconds and 4 git commands to generate.