Debian Codegraph @

test/lib/ansible_test/_internal/commands/coverage/erase.py

raw
1 """Erase code coverage files."""
2
3 from __future__ import annotations
4
5 import os
6
7 from ...util_common import (
8 ResultType,
9 )
10
11 from ...executor import (
12 Delegate,
13 )
14
15 from ...provisioning import (
16 prepare_profiles,
17 )
18
19 from . import (
20 CoverageConfig,
21 )
22
23
24 def command_coverage_erase(args: CoverageEraseConfig) -> None:
25 """Erase code coverage data files collected during test runs."""
26 host_state = prepare_profiles(args) # coverage erase
27
28 if args.delegate:
29 raise Delegate(host_state=host_state)
30
31 coverage_dir = ResultType.COVERAGE.path
32
33 for name in os.listdir(coverage_dir):
34 if not name.startswith('coverage') and '=coverage.' not in name:
35 continue
36
37 path = os.path.join(coverage_dir, name)
38
39 if not args.explain:
40 os.remove(path)
41
42
43 class CoverageEraseConfig(CoverageConfig):
44 """Configuration for the coverage erase command."""