Skip to content

Commit 321366b

Browse files
authored
read testcase ids from AS_TESTPLAN_IDS (via allure-framework#434)
1 parent 975aaf9 commit 321366b

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

allure-pytest/src/plugin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,17 @@ def select_by_labels(items, config):
148148

149149

150150
def select_by_testcase(items):
151-
file_path = os.environ.get("AS_TESTPLAN_PATH")
152151
ids = []
153-
if file_path:
152+
file_path = os.environ.get("AS_TESTPLAN_PATH")
153+
env_string = os.environ.get("AS_TESTPLAN_IDS")
154+
155+
if env_string:
156+
ids = set(env_string.strip().split(","))
157+
elif file_path:
154158
with open(file_path, 'r') as file:
155159
plan = json.load(file)
156160
ids = set([str(item.get("id")) for item in plan])
161+
157162
return filter(lambda item: ids & set(allure_label(item, LabelType.ID)) if ids else True, items)
158163

159164

allure-pytest/test/integration/allure_ee/select_by_testcase_id_test.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from hamcrest import assert_that, only_contains, any_of, ends_with
55

66

7+
@pytest.mark.parametrize("strategy", ["env_string", "env_path"])
78
@pytest.mark.parametrize(
89
["ids", "expected_tests"],
910
[
@@ -21,7 +22,7 @@
2122
),
2223
]
2324
)
24-
def test_select_by_testcase_id_test(ids, expected_tests, allured_testdir):
25+
def test_select_by_testcase_id_test(strategy, ids, expected_tests, allured_testdir):
2526
"""
2627
>>> import allure
2728
@@ -43,11 +44,14 @@ def test_select_by_testcase_id_test(ids, expected_tests, allured_testdir):
4344
"""
4445
allured_testdir.parse_docstring_source()
4546

46-
if ids:
47+
if strategy == "env_path" and ids:
4748
py_path = allured_testdir.testdir.makefile(".json", json.dumps(ids))
4849
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])
4952
else:
50-
del os.environ["AS_TESTPLAN_PATH"]
53+
os.environ.pop("AS_TESTPLAN_PATH", None)
54+
os.environ.pop("AS_TESTPLAN_IDS", None)
5155

5256
allured_testdir.run_with_allure()
5357
test_cases = [test_case["fullName"] for test_case in allured_testdir.allure_report.test_cases]

0 commit comments

Comments
 (0)