File: conftest.py

package info (click to toggle)
mkosi 26-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,564 kB
  • sloc: python: 20,615; sh: 640; makefile: 12
file content (64 lines) | stat: -rw-r--r-- 1,779 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# SPDX-License-Identifier: LGPL-2.1-or-later

from collections.abc import Iterator
from typing import Any, cast

import pytest

import mkosi.resources
from mkosi.config import parse_config
from mkosi.distribution import Distribution, detect_distribution
from mkosi.log import log_setup
from mkosi.util import resource_path

from . import ImageConfig, ci_group


def pytest_addoption(parser: Any) -> None:
    parser.addoption(
        "-D",
        "--distribution",
        metavar="DISTRIBUTION",
        help="Run the integration tests for the given distribution.",
        default=detect_distribution()[0],
        type=Distribution,
        choices=[Distribution(d) for d in Distribution.values()],
    )
    parser.addoption(
        "-R",
        "--release",
        metavar="RELEASE",
        help="Run the integration tests for the given release.",
    )
    parser.addoption(
        "--debug-shell",
        help="Pass --debug-shell when running mkosi",
        action="store_true",
    )


@pytest.fixture(scope="session")
def config(request: Any) -> ImageConfig:
    distribution = cast(Distribution, request.config.getoption("--distribution"))
    with resource_path(mkosi.resources) as resources:
        release = cast(
            str,
            request.config.getoption("--release")
            or parse_config(["-d", str(distribution)], resources=resources)[2][0].release,
        )
    return ImageConfig(
        distribution=distribution,
        release=release,
        debug_shell=request.config.getoption("--debug-shell"),
    )


@pytest.fixture(autouse=True)
def ci_sections(request: Any) -> Iterator[None]:
    with ci_group(request.node.name):
        yield


@pytest.fixture(scope="session", autouse=True)
def logging() -> None:
    log_setup()