]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume tests create a fixture for temporary files
authorAlfredo Deza <adeza@redhat.com>
Mon, 6 Nov 2017 14:42:53 +0000 (09:42 -0500)
committerAlfredo Deza <adeza@redhat.com>
Mon, 6 Nov 2017 16:04:00 +0000 (11:04 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/tests/conftest.py

index 764b0f4d74b1b80afc5d52b6fe48022312ac74fd..f5803346177d0e4b4ec996f754abb20d2f01e7ce 100644 (file)
@@ -1,3 +1,4 @@
+import os
 import pytest
 from ceph_volume.api import lvm as lvm_api
 
@@ -53,3 +54,17 @@ def is_root(monkeypatch):
     is root (or is sudoing to superuser) can continue as-is
     """
     monkeypatch.setattr('os.getuid', lambda: 0)
+
+
+@pytest.fixture
+def tmpfile(tmpdir):
+    """
+    Create a temporary file, optionally filling it with contents, returns an
+    absolute path to the file when called
+    """
+    def generate_file(name='file', contents=''):
+        path = os.path.join(str(tmpdir), name)
+        with open(path, 'w') as fp:
+            fp.write(contents)
+        return path
+    return generate_file