From 3e0105e0590d74e8deaf9a52a0009334e0bbe74f Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Mon, 18 Jan 2021 11:57:11 +0100 Subject: iotests.py: Assume a couple of variables as given There are a couple of environment variables that we fetch with os.environ.get() without supplying a default. Clearly they are required and expected to be set by the ./check script (as evidenced by execute_setup_common(), which checks for test_dir and qemu_default_machine to be set, and aborts if they are not). Using .get() this way has the disadvantage of returning an Optional[str] type, which mypy will complain about when tests just assume these values to be str. Use [] instead, which raises a KeyError for environment variables that are not set. When this exception is raised, catch it and move the abort code from execute_setup_common() there. Drop the 'assert iotests.sock_dir is not None' from iotest 300, because that sort of thing is precisely what this patch wants to prevent. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Willian Rampazzo Message-Id: <20210118105720.14824-2-mreitz@redhat.com> --- tests/qemu-iotests/300 | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/qemu-iotests/300') diff --git a/tests/qemu-iotests/300 b/tests/qemu-iotests/300 index 23aca59..38ef594 100755 --- a/tests/qemu-iotests/300 +++ b/tests/qemu-iotests/300 @@ -28,7 +28,6 @@ import qemu BlockBitmapMapping = List[Dict[str, Union[str, List[Dict[str, str]]]]] -assert iotests.sock_dir is not None mig_sock = os.path.join(iotests.sock_dir, 'mig_sock') -- cgit v1.1