Files
fm-orchestrator/tests/integration/conftest.py
Mariana Ulaieva a5f6d8f136 Factor out packaging utility
Until now, it was assumed that the module-build command returned only
one build, so it was only one build_id. However, it is possible that
the module-build command will build more than one builds and therefore
a list of build_ids is needed. Also is needed to watch and cancel more
than one build.
For this reason run, watch, and cancel methods are methods of the
PackagingUtility class instead of Build class.  Run method returns list
of Build objects instead of build_id. And it's also possible to cancel
and to watch on all generated module builds.
2020-01-23 14:26:46 +01:00

90 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
# SPDX-License-Identifier: MIT
import os
import sys
import tempfile
import pytest
import sh
import yaml
import utils
our_sh = sh(_out=sys.stdout, _err=sys.stderr, _tee=True)
from our_sh import pushd, Command # noqa
@pytest.fixture(scope="session")
def test_env():
"""Load test environment configuration
:return: Test environment configuration.
:rtype: dict
"""
config_file = os.getenv("MBS_TEST_CONFIG", "test.env.yaml")
with open(config_file) as f:
env = yaml.safe_load(f)
return env
@pytest.fixture(scope="session")
def pkg_util(test_env):
"""Fixture to interact with the packaging utility
:return: Packaging utility configured for the tests
:rtype: object of utils.PackagingUtility
"""
return utils.PackagingUtility(test_env["packaging_utility"], test_env["mbs_api"])
@pytest.fixture(scope="function")
def scenario(request, test_env):
"""Configuration data for the scenario
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.
:param pytest.FixtureRequest request: request object giving access
to the requesting test context
:param pytest.fixture test_env: test environment fixture
:return: repository object the tests can work with
:rtype: utils.Repo
"""
with tempfile.TemporaryDirectory() as tempdir:
packaging_util = Command(test_env["packaging_utility"]).bake(
_out=sys.stdout, _err=sys.stderr, _tee=True
)
args = [
"--branch",
scenario["branch"],
f"modules/{scenario['module']}",
tempdir,
]
packaging_util("clone", *args)
with pushd(tempdir):
yield utils.Repo(scenario["module"])
@pytest.fixture(scope="session")
def koji(test_env):
"""Koji session for the instance MBS is configured to work with
"""
return utils.Koji(**test_env["koji"])