Skip to content

Commit 919d3df

Browse files
authored
Fix --allure-severities argument of allure-pytest (fixes #260, #261) (#729)
1 parent efbebf7 commit 919d3df

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

allure-pytest/src/plugin.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import allure_commons
55
import os
66

7-
from allure_commons.types import LabelType
7+
from allure_commons.types import LabelType, Severity
88
from allure_commons.logger import AllureFileLogger
99
from allure_commons.utils import get_testplan
1010

@@ -44,7 +44,7 @@ def label_type(type_name, legal_values=set()):
4444
def a_label_type(string):
4545
atoms = set(string.split(','))
4646
if type_name is LabelType.SEVERITY:
47-
if not atoms < legal_values:
47+
if not atoms <= legal_values:
4848
raise argparse.ArgumentTypeError('Illegal {} values: {}, only [{}] are allowed'.format(
4949
type_name,
5050
', '.join(atoms - legal_values),
@@ -175,16 +175,25 @@ def pytest_configure(config):
175175

176176

177177
def select_by_labels(items, config):
178-
arg_labels = set().union(config.option.allure_epics,
179-
config.option.allure_features,
180-
config.option.allure_stories,
181-
config.option.allure_ids,
182-
config.option.allure_severities,
183-
*config.option.allure_labels)
178+
arg_labels = set().union(
179+
config.option.allure_epics,
180+
config.option.allure_features,
181+
config.option.allure_stories,
182+
config.option.allure_ids,
183+
config.option.allure_severities,
184+
*config.option.allure_labels
185+
)
184186
if arg_labels:
185187
selected, deselected = [], []
186188
for item in items:
187-
selected.append(item) if arg_labels & set(allure_labels(item)) else deselected.append(item)
189+
test_labels = set(allure_labels(item))
190+
test_severity = allure_label(item, LabelType.SEVERITY)
191+
if not test_severity:
192+
test_labels.add((LabelType.SEVERITY, Severity.NORMAL))
193+
if arg_labels & test_labels:
194+
selected.append(item)
195+
else:
196+
deselected.append(item)
188197
return selected, deselected
189198
else:
190199
return items, []

allure-pytest/test/acceptance/label/severity/select_severity_test.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,30 @@
77
@pytest.mark.parametrize(
88
["severities", "expected_tests"],
99
[
10-
(["critical", "minor"],
11-
[
12-
"test_vip",
13-
"test_minor"
14-
]),
15-
(["critical"],
16-
[
17-
"test_vip",
18-
]),
10+
pytest.param(
11+
["critical", "minor"],
12+
["test_vip", "test_minor"],
13+
id="critical,minor"
14+
),
15+
pytest.param(
16+
["critical"],
17+
["test_vip"],
18+
id="critical"
19+
),
20+
pytest.param(
21+
["normal"],
22+
["test_with_default_severity"],
23+
id="normal"
24+
),
25+
pytest.param(
26+
["trivial", "minor", "normal", "critical", "blocker"],
27+
[
28+
"test_vip",
29+
"test_with_default_severity",
30+
"test_minor"
31+
],
32+
id="all"
33+
)
1934
]
2035
)
2136
def test_select_by_severity_level(allured_testdir, severities, expected_tests):

0 commit comments

Comments
 (0)