From 92fad13dbf125a29927ddb5a2aece3fdd20b86d2 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 28 Apr 2021 14:13:11 +0000 Subject: [PATCH] test/sources: tmpdir as fixture Instead of creating the temporaroy directory within the unit test, provide it to the test via a test fixture. --- test/run/test_sources.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/run/test_sources.py b/test/run/test_sources.py index ee3438c5..b4d0981c 100644 --- a/test/run/test_sources.py +++ b/test/run/test_sources.py @@ -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)