diff mbox series

[v4,07/10] qemu-iotests: run python tests in own subdirectories

Message ID 72237c18d91644b1a7fe4cf39e4828240e7aac59.1508213452.git.jcody@redhat.com
State New
Headers show
Series qemu-iotests improvements | expand

Commit Message

Jeff Cody Oct. 17, 2017, 4:32 a.m. UTC
This adds the framework to iotests.py to run python iotests in a
subdirectory structure, structured like so:

scratch/
├── TestNumber
│   ├── TestClassName
│   │   ├── test_method_name

Prior to this patch, tests were run in a test subdirectory from
previous patches in the series, like this:

scratch/
├── TestNumber

However, given the nature of python's unittest framework, additional
subdirectories are needed, if we want to insure that we can save
intermediate files in case of test failures (as we will do in a
subsequent patch) without running the risk of tainting other test
methods from the test file.

In python tests using iiotests.QMPTestCase, any reference to
'iotests.test_dir' should be replaced by 'self.workdir'.  This
may also require changing the scope of path name variables.

Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Jeff Cody <jcody@redhat.com>
---
 tests/qemu-iotests/iotests.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 6f05790..bf9fe6f 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -262,6 +262,16 @@  index_re = re.compile(r'([^\[]+)\[([^\]]+)\]')
 class QMPTestCase(unittest.TestCase):
     '''Abstract base class for QMP test cases'''
 
+    def __init__(self, *args):
+        super(QMPTestCase, self).__init__(*args)
+        self.workdir = os.path.join(test_dir, self.__class__.__name__, self._testMethodName)
+        try:
+            os.makedirs(self.workdir)
+        except OSError, error:
+            if error.errno != errno.EEXIST:
+                raise
+        os.chdir(self.workdir)
+
     def dictpath(self, d, path):
         '''Traverse a path in a nested dict'''
         for component in path.split('/'):