summaryrefslogtreecommitdiff
path: root/tests/plugin_config.py
blob: bb6893e3ea19f1549c11b29d28cce9ccfa448b9c (plain)
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
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt

"""A configuring plugin for test_plugins.py to import."""

from __future__ import annotations

from typing import Any, List, cast

import coverage
from coverage.plugin_support import Plugins
from coverage.types import TConfigurable


class Plugin(coverage.CoveragePlugin):
    """A configuring plugin for testing."""
    def configure(self, config: TConfigurable) -> None:
        """Configure all the things!"""
        opt_name = "report:exclude_lines"
        exclude_lines = cast(List[str], config.get_option(opt_name))
        exclude_lines.append(r"pragma: custom")
        exclude_lines.append(r"pragma: or whatever")
        config.set_option(opt_name, exclude_lines)


def coverage_init(
    reg: Plugins,
    options: Any,           # pylint: disable=unused-argument
) -> None:
    """Called by coverage to initialize the plugins here."""
    reg.add_configurer(Plugin())