diff --git a/osbuild/loop.py b/osbuild/loop.py index a9345279..77334c3f 100644 --- a/osbuild/loop.py +++ b/osbuild/loop.py @@ -120,6 +120,7 @@ class Loop: self.devname = f"loop{minor}" self.minor = minor self.on_close = None + self.fd = -1 with contextlib.ExitStack() as stack: if not dir_fd: diff --git a/test/mod/test_loop.py b/test/mod/test_loop.py index 9422114d..0b5ba6bb 100644 --- a/test/mod/test_loop.py +++ b/test/mod/test_loop.py @@ -253,3 +253,8 @@ def test_on_close(tempdir): lo.close() ctl.close() + + +def test_loop_handles_error_in_init(): + with pytest.raises(FileNotFoundError): + lopo = loop.Loop("non-existing")