From 23da3445718c01f71e2a5748fb4fc1c5fdc85ca5 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Mon, 6 Nov 2017 09:42:53 -0500 Subject: [PATCH] ceph-volume tests create a fixture for temporary files Signed-off-by: Alfredo Deza --- src/ceph-volume/ceph_volume/tests/conftest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ceph-volume/ceph_volume/tests/conftest.py b/src/ceph-volume/ceph_volume/tests/conftest.py index 764b0f4d74b1b..f5803346177d0 100644 --- a/src/ceph-volume/ceph_volume/tests/conftest.py +++ b/src/ceph-volume/ceph_volume/tests/conftest.py @@ -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 -- 2.39.5