File: conftest.py

package info (click to toggle)
kombu 5.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,924 kB
  • sloc: python: 27,919; makefile: 318; sh: 8
file content (35 lines) | stat: -rw-r--r-- 1,063 bytes parent folder | download | duplicates (2)
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
from __future__ import annotations

import pytest


def pytest_addoption(parser):
    parser.addoption(
        "-E",
        action="append",
        metavar="NAME",
        help="only run tests matching the environment NAME.",
    )


def pytest_configure(config):
    # register an additional marker
    config.addinivalue_line(
        "markers",
        "env(name): mark test to run only on named environment",
    )
    config.addinivalue_line("markers", "replace_module_value")
    config.addinivalue_line("markers", "masked_modules")
    config.addinivalue_line("markers", "ensured_modules")
    config.addinivalue_line("markers", "sleepdeprived_patched_module")


def pytest_runtest_setup(item):
    envnames = [mark.args[0] for mark in item.iter_markers(name='env')]
    if envnames:
        if (
            item.config.getoption("-E") is None
            or len(set(item.config.getoption("-E")) & set(envnames)) == 0
        ):
            # We skip test if does not mentioned by -E param
            pytest.skip("test requires env in %r" % envnames)