iotests.py: add FilePath context manager
commitf4844ac0adabc458ba4610a71155448783d37c73
authorStefan Hajnoczi <stefanha@redhat.com>
Thu, 24 Aug 2017 07:22:01 +0000 (24 08:22 +0100)
committerStefan Hajnoczi <stefanha@redhat.com>
Tue, 5 Sep 2017 09:32:07 +0000 (5 10:32 +0100)
tree0ec001714e54cb687cc49e3b98f01b40617ca222
parentd792bc3811f22a22a46c7d9a725fd29029f54095
iotests.py: add FilePath context manager

The scratch/ (TEST_DIR) directory is not automatically cleaned up after
test execution.  It is the responsibility of tests to remove any files
they create.

A nice way of doing this is to declare files at the beginning of the
test and automatically remove them with a context manager:

  with iotests.FilePath('test.img') as img_path:
      qemu_img(...)
      qemu_io(...)
  # img_path is guaranteed to be deleted here

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 20170824072202.26818-3-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
tests/qemu-iotests/iotests.py