Skip to content

Commit b6a166c

Browse files
authored
select tests by fullName (via #478)
1 parent 63779d2 commit b6a166c

File tree

7 files changed

+68
-31
lines changed

7 files changed

+68
-31
lines changed

allure-behave/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
envlist =
33
py{36,37}
4-
static_check
4+
static-check
55

66
[testenv]
77
passenv = HOME

allure-pytest/src/plugin.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from allure_commons.logger import AllureFileLogger
1010

1111

12-
from allure_pytest.utils import allure_label, allure_labels
12+
from allure_pytest.utils import allure_label, allure_labels, allure_full_name
1313
from allure_pytest.helper import AllureTestHelper
1414
from allure_pytest.listener import AllureListener
1515

@@ -148,18 +148,18 @@ def select_by_labels(items, config):
148148

149149

150150
def select_by_testcase(items):
151-
ids = []
151+
plan = []
152152
file_path = os.environ.get("AS_TESTPLAN_PATH")
153-
env_string = os.environ.get("AS_TESTPLAN_IDS")
154153

155-
if env_string:
156-
ids = set(env_string.strip().split(","))
157-
elif file_path:
158-
with open(file_path, 'r') as file:
159-
plan = json.load(file)
160-
ids = set([str(item.get("id")) for item in plan])
154+
if file_path:
155+
with open(file_path, 'r') as plan_file:
156+
plan = json.load(plan_file)
161157

162-
return filter(lambda item: ids & set(allure_label(item, LabelType.ID)) if ids else True, items)
158+
return filter(lambda item: any(
159+
[str(planed_item.get("id")) in [str(allure_id) for allure_id in allure_label(item, LabelType.ID)]
160+
or
161+
(planed_item.get("selector") == allure_full_name(item))
162+
for planed_item in plan]), items) if plan else items
163163

164164

165165
def pytest_collection_modifyitems(items, config):
Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,62 @@
11
import pytest
22
import json
33
import os
4-
from hamcrest import assert_that, only_contains, any_of, ends_with
4+
from hamcrest import assert_that, contains_inanyorder, ends_with
55

66

7-
@pytest.mark.parametrize("strategy", ["env_string", "env_path"])
87
@pytest.mark.parametrize(
9-
["ids", "expected_tests"],
8+
["plan_json", "expected_tests"],
109
[
10+
# by ids only
1111
(
1212
[{"id": 1}, {"id": 2}],
1313
["test_number_one", "test_number_two"]
1414
),
15+
16+
# by ids for multiply decorated test
1517
(
1618
[{"id": 1}, {"id": 3}, {"id": 4}],
1719
["test_number_one", "test_number_three"]
1820
),
21+
22+
# by wrong id
23+
(
24+
[{"id": 1234}],
25+
[]
26+
),
27+
28+
# by selectors only
29+
(
30+
[{"selector": "test_number_one"}, {"selector": "test_number_three"}],
31+
["test_number_one", "test_number_three"]
32+
),
33+
34+
# by selector for not decorated with id test
35+
(
36+
[{"selector": "test_without_number"}],
37+
["test_without_number"]
38+
),
39+
40+
# by id and selector for same test
41+
(
42+
[{"id": 2, "selector": "test_number_two"}],
43+
["test_number_two"]
44+
),
45+
46+
# by wrong selector
47+
(
48+
[{"selector": "test_without_never"}],
49+
[]
50+
),
51+
52+
# without plan
1953
(
2054
None,
2155
["test_number_one", "test_number_two", "test_number_three", "test_without_number"]
2256
),
2357
]
2458
)
25-
def test_select_by_testcase_id_test(strategy, ids, expected_tests, allured_testdir):
59+
def test_select_by_testcase_id_test(plan_json, expected_tests, allured_testdir, request):
2660
"""
2761
>>> import allure
2862
@@ -42,21 +76,24 @@ def test_select_by_testcase_id_test(strategy, ids, expected_tests, allured_testd
4276
>>> def test_without_number():
4377
... pass
4478
"""
45-
allured_testdir.parse_docstring_source()
4679

47-
if strategy == "env_path" and ids:
48-
py_path = allured_testdir.testdir.makefile(".json", json.dumps(ids))
80+
root_dir = request.config.rootdir.strpath
81+
test_dir = allured_testdir.testdir.tmpdir.strpath.replace(root_dir, "")
82+
full_name_base_template = "{base}.test_select_by_testcase_id_test".format(
83+
base=test_dir.strip(os.sep).replace(os.sep, "."))
84+
85+
if plan_json:
86+
for item in plan_json:
87+
if "selector" in item:
88+
item["selector"] = "{base}#{name}".format(base=full_name_base_template, name=item["selector"])
89+
py_path = allured_testdir.testdir.makefile(".json", json.dumps(plan_json))
4990
os.environ["AS_TESTPLAN_PATH"] = py_path.strpath
50-
elif strategy == "env_string" and ids:
51-
os.environ["AS_TESTPLAN_IDS"] = ",".join([str(item["id"]) for item in ids])
5291
else:
5392
os.environ.pop("AS_TESTPLAN_PATH", None)
54-
os.environ.pop("AS_TESTPLAN_IDS", None)
5593

94+
allured_testdir.parse_docstring_source()
5695
allured_testdir.run_with_allure()
57-
test_cases = [test_case["fullName"] for test_case in allured_testdir.allure_report.test_cases]
58-
assert_that(test_cases, only_contains(
59-
any_of(
60-
*[ends_with(name) for name in expected_tests]
61-
)
62-
))
96+
97+
executed_full_names = [test_case["fullName"] for test_case in allured_testdir.allure_report.test_cases]
98+
99+
assert_that(executed_full_names, contains_inanyorder(*[ends_with(name) for name in expected_tests]))

allure-pytest/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ envlist =
33
py{36,37}
44
xdist
55
integration
6-
static_check
6+
static-check
77

88

99
[testenv]

allure-python-commons/src/mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __is(kind, t):
1313
return kind in [v for k, v in t.__dict__.items() if not k.startswith('__')]
1414

1515

16-
def parse_tag(tag, *, issue_pattern=None, link_pattern=None):
16+
def parse_tag(tag, issue_pattern=None, link_pattern=None):
1717
"""
1818
>>> parse_tag("blocker")
1919
Label(name='severity', value='blocker')

allure-python-commons/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
envlist=
33
py{36,37}
4-
static_check
4+
static-check
55

66

77
[testenv]

allure-robotframework/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
envlist=
33
py{36,37}
4-
static_check
4+
static-check
55

66

77
[testenv]

0 commit comments

Comments
 (0)