-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathregressions.py
123 lines (101 loc) · 3.12 KB
/
regressions.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
from collections import defaultdict
import re
import warnings
import pytest
def load(rules):
"""
Parses the regression section of the conf file and returns a two level dict with format:
{<test_name>:
{<test_id>: <comment>
...
}
...
}
Examples:
>>> load([
... {
... 'test_name': 'test_foo',
... 'test_param_id': 'foo-id',
... 'comment': 'foo bar baz!'
... }
... ]) == {'test_foo': {'foo-id': 'foo bar baz!'}}
True
>>> load([
... {
... 'test_name': 'test_foo',
... 'test_param_id': 'foo-id',
... 'comment': 'foo bar baz!'
... },
... {
... 'test_name': 'test_foo',
... 'test_param_id': 'bar-id',
... 'comment': 'bar bar baz!'
... }
... ]) == {
... 'test_foo': {
... 'foo-id': 'foo bar baz!',
... 'bar-id': 'bar bar baz!' }}
True
Duplicate test name and IDs are ignored with a warning:
>>> load([
... {
... 'test_name': 'test_foo',
... 'test_param_id': 'foo-id',
... 'comment': 'foo bar baz!'
... },
... {
... 'test_name': 'test_foo',
... 'test_param_id': 'foo-id',
... 'comment': 'bar bar baz!'
... }
... ]) == {'test_foo': {'foo-id': 'foo bar baz!'}}
True
>>> # UserWarning: Regressions: test_name: test_foo | test_id: foo-id | Skipping duplicate test name and ID
Does not check that test name and IDs exist (since names might not
be collected and IDs can require an HTTP call).
"""
processed_rules = defaultdict(dict)
if not rules:
return processed_rules
for rule in rules:
test_name, test_id, comment = (
rule["test_name"],
rule["test_param_id"],
rule["comment"],
)
if test_id in processed_rules[test_name]:
warnings.warn(
"Regressions: test_name: {} | test_id: {} | Skipping duplicate test name and ID".format(
test_name, test_id
)
)
continue
processed_rules[test_name][test_id] = comment
return processed_rules
# TODO: This is fairly similar to exemptions.add_xfail_marker
def add_regression_marker(item):
"""
Adds regression markers as specified in the config file.
"""
if not item.get_marker("parametrize"):
warnings.warn(
"Skipping regression checks for test without resource name {!r}".format(
item.name
)
)
return
test_regressions = item.config.custom_config.regressions.get(
item.originalname, None
)
test_id = item._genid
if test_regressions:
for regression_test_id in test_regressions:
if regression_test_id.startswith("*"):
substring = regression_test_id[1:]
if re.search(substring, test_id):
comment = test_regressions[regression_test_id]
item.add_marker(pytest.mark.regression(comment))
return
if test_id in test_regressions:
comment = test_regressions[test_id]
item.add_marker(pytest.mark.regression(comment))