Skip to content

Commit

Permalink
read testcase ids from AS_TESTPLAN_IDS (via allure-framework#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
sseliverstov authored Oct 8, 2019
1 parent 5fc9f3c commit fc8af70
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions allure-pytest/src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,17 @@ def select_by_labels(items, config):


def select_by_testcase(items):
file_path = os.environ.get("AS_TESTPLAN_PATH")
ids = []
if file_path:
file_path = os.environ.get("AS_TESTPLAN_PATH")
env_string = os.environ.get("AS_TESTPLAN_IDS")

if env_string:
ids = set(env_string.strip().split(","))
elif file_path:
with open(file_path, 'r') as file:
plan = json.load(file)
ids = set([str(item.get("id")) for item in plan])

return filter(lambda item: ids & set(allure_label(item, LabelType.ID)) if ids else True, items)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from hamcrest import assert_that, only_contains, any_of, ends_with


@pytest.mark.parametrize("strategy", ["env_string", "env_path"])
@pytest.mark.parametrize(
["ids", "expected_tests"],
[
Expand All @@ -21,7 +22,7 @@
),
]
)
def test_select_by_testcase_id_test(ids, expected_tests, allured_testdir):
def test_select_by_testcase_id_test(strategy, ids, expected_tests, allured_testdir):
"""
>>> import allure
Expand All @@ -43,11 +44,14 @@ def test_select_by_testcase_id_test(ids, expected_tests, allured_testdir):
"""
allured_testdir.parse_docstring_source()

if ids:
if strategy == "env_path" and ids:
py_path = allured_testdir.testdir.makefile(".json", json.dumps(ids))
os.environ["AS_TESTPLAN_PATH"] = py_path.strpath
elif strategy == "env_string" and ids:
os.environ["AS_TESTPLAN_IDS"] = ",".join([str(item["id"]) for item in ids])
else:
del os.environ["AS_TESTPLAN_PATH"]
os.environ.pop("AS_TESTPLAN_PATH", None)
os.environ.pop("AS_TESTPLAN_IDS", None)

allured_testdir.run_with_allure()
test_cases = [test_case["fullName"] for test_case in allured_testdir.allure_report.test_cases]
Expand Down

0 comments on commit fc8af70

Please sign in to comment.