test/sources: tmpdir as fixture

Instead of creating the temporaroy directory within the unit test,
provide it to the test via a test fixture.
This commit is contained in:
Christian Kellner 2021-04-28 14:13:11 +00:00
parent 518940cfe0
commit 92fad13dbf

View file

@ -97,9 +97,15 @@ def check_case(source, case, store, libdir):
raise ValueError(f"invalid expectation: {expects}")
@pytest.fixture(name="tmpdir")
def tmpdir_fixture():
with tempfile.TemporaryDirectory() as tmp:
yield tmp
@pytest.mark.skipif(not can_setup_netns(), reason="network namespace setup failed")
@pytest.mark.parametrize("source,case", make_test_cases())
def test_sources(source, case):
def test_sources(source, case, tmpdir):
index = osbuild.meta.Index(os.curdir)
sources = os.path.join(test.TestBase.locate_test_data(), "sources")
@ -113,8 +119,7 @@ def test_sources(source, case):
src = osbuild.sources.Source(info, items, options)
with tempfile.TemporaryDirectory() as tmpdir, \
osbuild.objectstore.ObjectStore(tmpdir) as store, \
with osbuild.objectstore.ObjectStore(tmpdir) as store, \
fileServer(test.TestBase.locate_test_data()):
check_case(src, case_options, store, index.path)
check_case(src, case_options, store, index.path)