From c616afa87efa2ddba16e3d72362cec699fd4d4fe Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 10 Mar 2021 21:13:03 +0000 Subject: [PATCH] test: dynamically generate stage test_stages This is a partial revert of commit d584a1e, which converted the dynamically generate stage tests to sub tests. The problem with the latter is that they can't be individually run, which makes testing changes to specific stages cumbersome to develop. Therefore switch back to a model where the stage tests are dynamically generated via a class decorator. --- test/run/test_stages.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/run/test_stages.py b/test/run/test_stages.py index 212f4874..9cf6dc7b 100644 --- a/test/run/test_stages.py +++ b/test/run/test_stages.py @@ -30,9 +30,20 @@ def find_stage(result, stageid): return None +def make_stage_tests(klass): + path = os.path.join(test.TestBase.locate_test_data(), "stages") + for t in glob.glob(f"{path}/*/diff.json"): + test_path = os.path.dirname(t) + test_name = os.path.basename(test_path).replace("-", "_") + setattr(klass, f"test_{test_name}", + lambda s, path=test_path: s.run_stage_diff_test(path)) + return klass + + @unittest.skipUnless(test.TestBase.have_test_data(), "no test-data access") @unittest.skipUnless(test.TestBase.have_tree_diff(), "tree-diff missing") @unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only") +@make_stage_tests class TestStages(test.TestBase): def assertTreeDiffsEqual(self, tree_diff1, tree_diff2): @@ -180,14 +191,6 @@ class TestStages(test.TestBase): # the osbuild cache with. osb.copy_source_data(self.store, "org.osbuild.files") - def test_stages(self): - path = os.path.join(self.locate_test_data(), "stages") - for t in glob.glob(f"{path}/*/diff.json"): - test_path = os.path.dirname(t) - test_name = os.path.basename(test_path) - with self.subTest(stage=test_name): - self.run_stage_diff_test(test_path) - def test_dracut(self): datadir = self.locate_test_data() base = os.path.join(datadir, "stages/dracut")