Tests: Create a fixture for scenario configuration

Until now, to access the configuration of a scenario, the full path in
test_env had to be specified.

This might be cumbersome and error prone.

Create a scenario fixture, to make it easier to access the same
configuration.

Instead of

    test_env["testdata"]["my_scenario"]["my_config"]

one can use the following:

    scenario["my_config"]

Signed-off-by: Hunor Csomortáni <csomh@redhat.com>
This commit is contained in:
Hunor Csomortáni
2019-12-20 14:12:48 +01:00
parent 351eb671f6
commit 5f7442f8c1
8 changed files with 42 additions and 31 deletions

View File

@@ -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")

View File

@@ -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)

View File

@@ -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"

View File

@@ -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

View File

@@ -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.

View File

@@ -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")

View File

@@ -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()

View File

@@ -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()