-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathconfigure.py
161 lines (121 loc) · 3.6 KB
/
configure.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import sys
import re
try:
from coverage.tracer import CTracer as Tracer # pylint: disable=no-name-in-module
except ImportError:
from coverage.pytracer import PyTracer as Tracer
from dataclasses import dataclass
def _is_dogfooding(coverage_stack):
return coverage_stack
def _is_debugger():
return sys.gettrace() and not isinstance(sys.gettrace(), Tracer)
def _is_coverage():
return False
def _get_notestmon_reasons(options):
if options["no-testmon"]:
return "deactivated through --no-testmon"
if not any(
options.get(t, False)
for t in [
"testmon",
"testmon_noselect",
"testmon_nocollect",
"testmon_forceselect",
"tmnet",
]
):
return "not mentioned"
return None
def _get_nocollect_reasons(
options,
debugger=False,
coverage=False,
dogfooding=False,
cov_plugin=False,
):
if options["testmon_nocollect"]:
return [None]
if cov_plugin:
return []
if coverage and not dogfooding:
return ["coverage.py was detected and simultaneous collection is not supported"]
if debugger and not dogfooding:
return ["it's not compatible with debugger"]
return []
def _get_noselect_reasons(options):
if options["testmon_forceselect"]:
return []
if options["testmon_noselect"]:
return [None]
if options["keyword"]:
return ["-k was used"]
if options["markexpr"]:
return ["-m was used"]
if options["lf"]:
return ["--lf was used"]
if any(re.match(r"(.*)\.py::(.*)", opt) for opt in options["file_or_dir"] or []):
return ["you selected tests manually"]
return []
def _formulate_deactivation(what, reasons):
if reasons:
return [
f"{what} automatically deactivated because {reasons[0]}, "
if reasons[0]
else what + " deactivated, "
]
return []
@dataclass
class TmConf:
message: str
collect: bool
select: bool
tmnet: bool = False
def __eq__(self, other):
return (
self.message == other.message
and self.collect == other.collect
and self.select == other.select
and self.tmnet == other.tmnet
)
def _header_collect_select(
options,
debugger=False,
coverage=False,
dogfooding=False,
cov_plugin=False,
) -> TmConf:
notestmon_reasons = _get_notestmon_reasons(options)
if notestmon_reasons == "not mentioned":
return TmConf(None, False, False)
if notestmon_reasons:
return TmConf("testmon: " + notestmon_reasons, False, False)
nocollect_reasons = _get_nocollect_reasons(
options,
debugger=debugger,
coverage=coverage,
dogfooding=dogfooding,
cov_plugin=cov_plugin,
)
noselect_reasons = _get_noselect_reasons(options)
if nocollect_reasons or noselect_reasons:
message = "".join(
_formulate_deactivation("collection", nocollect_reasons)
+ _formulate_deactivation("selection", noselect_reasons)
)
else:
message = ""
return TmConf(
f"testmon: {message}",
not bool(nocollect_reasons),
not bool(noselect_reasons),
bool(options.get("tmnet")),
)
def header_collect_select(config, coverage_stack, cov_plugin=None) -> TmConf:
options = vars(config.option)
return _header_collect_select(
options,
debugger=_is_debugger(),
coverage=_is_coverage(),
dogfooding=_is_dogfooding(coverage_stack),
cov_plugin=cov_plugin,
)