[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 01/17] iotests: use with-statement for open() calls
From: |
John Snow |
Subject: |
[PATCH v2 01/17] iotests: use with-statement for open() calls |
Date: |
Tue, 20 Jul 2021 13:33:20 -0400 |
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 <jsnow@redhat.com>
---
tests/qemu-iotests/iotests.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 89663dac06d..beadf5c821c 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -1075,7 +1075,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)
@@ -1088,8 +1089,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:
--
2.31.1
- [PATCH v2 00/17] python/iotests: Run iotest linters during Python CI, John Snow, 2021/07/20
- [PATCH v2 01/17] iotests: use with-statement for open() calls,
John Snow <=
- [PATCH v2 04/17] iotests/migrate-bitmaps-postcopy-test: declare instance variables, John Snow, 2021/07/20
- [PATCH v2 03/17] iotests/mirror-top-perms: Adjust import paths, John Snow, 2021/07/20
- [PATCH v2 02/17] iotests: use subprocess.DEVNULL instead of open("/dev/null"), John Snow, 2021/07/20
- [PATCH v2 06/17] iotests/297: modify is_python_file to work from any CWD, John Snow, 2021/07/20
- [PATCH v2 05/17] iotests/migrate-bitmaps-test: delint, John Snow, 2021/07/20
- [PATCH v2 07/17] iotests/297: Add get_files() function, John Snow, 2021/07/20
- [PATCH v2 08/17] iotests/297: Include sub-directories when finding tests to lint, John Snow, 2021/07/20