diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 1a710a30..17478744 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -29,11 +29,24 @@ def test_env(): @pytest.fixture(scope="function") -def repo(request, test_env): - """Clone the module repo to be used by the test +def scenario(request, test_env): + """Configuration data for the scenario - Find out the name of the test (anything that follow "test_"), and get - the corresponding module repo from the test environment configuration. + Find out the name of the scenario (anything that follows "test_"), + and return the corresponding configuration. + + This is a convenience fixture to serve as a shortcut to access + scenario configuration. + """ + scenario_name = request.function.__name__.split("test_", 1)[1] + return test_env["testdata"][scenario_name] + + +@pytest.fixture(scope="function") +def repo(scenario, test_env): + """Clone the module repo to be used by the scenario + + Get the module repo from the scenario configuration. Clone the repo in a temporary location and switch the current working directory into it. @@ -45,20 +58,18 @@ def repo(request, test_env): :rtype: utils.Repo """ with tempfile.TemporaryDirectory() as tempdir: - testname = request.function.__name__.split("test_", 1)[1] - repo_conf = test_env["testdata"][testname] packaging_util = Command(test_env["packaging_utility"]).bake( _out=sys.stdout, _err=sys.stderr, _tee=True ) args = [ "--branch", - repo_conf["branch"], - f"modules/{repo_conf['module']}", + scenario["branch"], + f"modules/{scenario['module']}", tempdir, ] packaging_util("clone", *args) with pushd(tempdir): - yield utils.Repo(repo_conf["module"]) + yield utils.Repo(scenario["module"]) @pytest.fixture(scope="session") diff --git a/tests/integration/test_failed_build.py b/tests/integration/test_failed_build.py index 9ef644c8..9ee6b391 100644 --- a/tests/integration/test_failed_build.py +++ b/tests/integration/test_failed_build.py @@ -4,7 +4,7 @@ import utils -def test_failed_build(test_env, repo, koji): +def test_failed_build(test_env, scenario, repo, koji): """ Run the build with "rebuild_strategy=all". @@ -18,14 +18,14 @@ def test_failed_build(test_env, repo, koji): build.run( "--optional", "rebuild_strategy=all", - reuse=test_env["testdata"]["failed_build"].get("build_id"), + reuse=scenario.get("build_id"), ) build.watch() assert build.state_name == "failed" - batch = test_env["testdata"]["failed_build"]["batch"] - failing_components = test_env["testdata"]["failed_build"]["failing_components"] - canceled_components = test_env["testdata"]["failed_build"]["canceled_components"] + batch = scenario["batch"] + failing_components = scenario["failing_components"] + canceled_components = scenario["canceled_components"] assert sorted(failing_components) == sorted(build.component_names(state="FAILED", batch=batch)) assert sorted(canceled_components) == sorted( build.component_names(state="COMPLETE", batch=batch) diff --git a/tests/integration/test_no_components.py b/tests/integration/test_no_components.py index ef5756c6..36bddf2b 100644 --- a/tests/integration/test_no_components.py +++ b/tests/integration/test_no_components.py @@ -4,7 +4,7 @@ import utils -def test_no_components(test_env, repo, koji): +def test_no_components(test_env, scenario, repo, koji): """ Submit the testmodule build with `fedpkg module-build` @@ -15,7 +15,7 @@ def test_no_components(test_env, repo, koji): """ build = utils.Build(test_env["packaging_utility"], test_env["mbs_api"]) repo.bump() - build.run(reuse=test_env["testdata"]["no_components"].get("build_id")) + build.run(reuse=scenario.get("build_id")) build.watch() assert build.state_name == "ready" diff --git a/tests/integration/test_normal_build.py b/tests/integration/test_normal_build.py index 0dece3e2..061ffbfb 100644 --- a/tests/integration/test_normal_build.py +++ b/tests/integration/test_normal_build.py @@ -4,7 +4,7 @@ import utils -def test_normal_build(test_env, repo, koji): +def test_normal_build(test_env, scenario, repo, koji): """ Run build with `rhpkg-stage module-build --optional rebuild_strategy=all` @@ -22,13 +22,13 @@ def test_normal_build(test_env, repo, koji): build_id = build.run( "--optional", "rebuild_strategy=all", - reuse=test_env["testdata"]["normal_build"].get("build_id"), + reuse=scenario.get("build_id"), ) build.watch() assert sorted(build.component_names()) == sorted(repo.components + ["module-build-macros"]) - expected_buildorder = test_env["testdata"]["normal_build"]["buildorder"] + expected_buildorder = scenario["buildorder"] expected_buildorder = [set(batch) for batch in expected_buildorder] actual_buildorder = build.batches() assert actual_buildorder == expected_buildorder @@ -41,7 +41,7 @@ def test_normal_build(test_env, repo, koji): modulemd = koji.get_modulemd(cg_build) actual_platforms = modulemd["data"]["dependencies"][0]["buildrequires"]["platform"] expected_platforms = repo.platform - platform_ga = test_env["testdata"]["normal_build"].get("platform_is_ga") + platform_ga = scenario.get("platform_is_ga") if platform_ga: expected_platforms = [f"{pf}.z" for pf in expected_platforms] assert expected_platforms == actual_platforms diff --git a/tests/integration/test_resume_cancelled_build.py b/tests/integration/test_resume_cancelled_build.py index e27ff15e..c56c5832 100644 --- a/tests/integration/test_resume_cancelled_build.py +++ b/tests/integration/test_resume_cancelled_build.py @@ -5,7 +5,7 @@ import utils import time -def test_resume_cancelled_build(test_env, repo, koji): +def test_resume_cancelled_build(test_env, scenario, repo, koji): """ Run the build with "rebuild_strategy=all". Wait until the module-build-macros build is submitted to Koji. diff --git a/tests/integration/test_reuse_all_components.py b/tests/integration/test_reuse_all_components.py index d856361f..da7f27da 100644 --- a/tests/integration/test_reuse_all_components.py +++ b/tests/integration/test_reuse_all_components.py @@ -4,7 +4,7 @@ import utils -def test_reuse_all_components(test_env, repo, koji): +def test_reuse_all_components(test_env, scenario, repo, koji): """Rebuild the test module again, without changing any of the components with: `fedpkg module-build -w --optional rebuild_strategy=only-changed` @@ -19,7 +19,7 @@ def test_reuse_all_components(test_env, repo, koji): "--watch", "--optional", "rebuild_strategy=all", - reuse=test_env["testdata"]["reuse_all_components"].get("build_id"), + reuse=scenario.get("build_id"), ) task_ids = build.component_task_ids() task_ids.pop("module-build-macros") @@ -29,7 +29,7 @@ def test_reuse_all_components(test_env, repo, koji): "-w", "--optional", "rebuild_strategy=only-changed", - reuse=test_env["testdata"]["reuse_all_components"].get("build_id_reused")) + reuse=scenario.get("build_id_reused")) reused_task_ids = build.component_task_ids() assert not build.components(package="module-build-macros") diff --git a/tests/integration/test_reuse_components.py b/tests/integration/test_reuse_components.py index 72ec7473..d4a49637 100644 --- a/tests/integration/test_reuse_components.py +++ b/tests/integration/test_reuse_components.py @@ -4,7 +4,7 @@ import utils -def test_reuse_components(test_env, repo, koji): +def test_reuse_components(test_env, scenario, repo, koji): """ Bump the commit of one of the components that MBS uses. Bump the commit of the same testmodule that was mentioned in the preconditions. @@ -21,13 +21,13 @@ def test_reuse_components(test_env, repo, koji): "--watch", "--optional", "rebuild_strategy=all", - reuse=test_env["testdata"]["reuse_components"].get("baseline_build_id"), + reuse=scenario.get("baseline_build_id"), ) - package = test_env["testdata"]["reuse_components"].get("package") + package = scenario.get("package") component = utils.Component( package, - test_env["testdata"]["reuse_components"].get("component_branch") + scenario.get("component_branch") ) component.clone(test_env["packaging_utility"]) component.bump() @@ -38,7 +38,7 @@ def test_reuse_components(test_env, repo, koji): "--watch", "--optional", "rebuild_strategy=only-changed", - reuse=test_env["testdata"]["reuse_components"].get("build_id"), + reuse=scenario.get("build_id"), ) comp_task_ids_base = baseline_build.component_task_ids() diff --git a/tests/integration/test_scratch_build.py b/tests/integration/test_scratch_build.py index f7182f61..e33a4199 100644 --- a/tests/integration/test_scratch_build.py +++ b/tests/integration/test_scratch_build.py @@ -4,7 +4,7 @@ import utils -def test_scratch_build(test_env, repo, koji): +def test_scratch_build(test_env, scenario, repo, koji): """ Run a scratch build with "rebuild_strategy=all". @@ -19,7 +19,7 @@ def test_scratch_build(test_env, repo, koji): "--scratch", "--optional", "rebuild_strategy=all", - reuse=test_env["testdata"]["scratch_build"].get("build_id"), + reuse=scenario.get("build_id"), ) build.watch()