From 80ec3e7c0b71f7419209d07e3201383f5850d7e7 Mon Sep 17 00:00:00 2001 From: Stas Seliverstov Date: Tue, 7 Apr 2020 16:35:39 +0300 Subject: [PATCH] change testplan format --- allure-pytest/src/plugin.py | 5 +++-- ..._id_test.py => select_test_from_testplan_test.py} | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) rename allure-pytest/test/integration/allure_ee/{select_by_testcase_id_test.py => select_test_from_testplan_test.py} (90%) diff --git a/allure-pytest/src/plugin.py b/allure-pytest/src/plugin.py index dbf9a62a..2bf5af23 100644 --- a/allure-pytest/src/plugin.py +++ b/allure-pytest/src/plugin.py @@ -148,18 +148,19 @@ def select_by_labels(items, config): def select_by_testcase(items): - plan = [] + planned_tests = [] file_path = os.environ.get("AS_TESTPLAN_PATH") if file_path: with open(file_path, 'r') as plan_file: plan = json.load(plan_file) + planned_tests = plan.get("tests", []) return filter(lambda item: any( [str(planed_item.get("id")) in [str(allure_id) for allure_id in allure_label(item, LabelType.ID)] or (planed_item.get("selector") == allure_full_name(item)) - for planed_item in plan]), items) if plan else items + for planed_item in planned_tests]), items) if planned_tests else items def pytest_collection_modifyitems(items, config): diff --git a/allure-pytest/test/integration/allure_ee/select_by_testcase_id_test.py b/allure-pytest/test/integration/allure_ee/select_test_from_testplan_test.py similarity index 90% rename from allure-pytest/test/integration/allure_ee/select_by_testcase_id_test.py rename to allure-pytest/test/integration/allure_ee/select_test_from_testplan_test.py index 6aea429f..ee1c39ec 100644 --- a/allure-pytest/test/integration/allure_ee/select_by_testcase_id_test.py +++ b/allure-pytest/test/integration/allure_ee/select_test_from_testplan_test.py @@ -5,7 +5,7 @@ @pytest.mark.parametrize( - ["plan_json", "expected_tests"], + ["planned_tests", "expected_tests"], [ # by ids only ( @@ -56,7 +56,7 @@ ), ] ) -def test_select_by_testcase_id_test(plan_json, expected_tests, allured_testdir, request): +def test_select_by_testcase_id_test(planned_tests, expected_tests, allured_testdir, request): """ >>> import allure @@ -82,11 +82,13 @@ def test_select_by_testcase_id_test(plan_json, expected_tests, allured_testdir, full_name_base_template = "{base}.test_select_by_testcase_id_test".format( base=test_dir.strip(os.sep).replace(os.sep, ".")) - if plan_json: - for item in plan_json: + if planned_tests: + for item in planned_tests: if "selector" in item: item["selector"] = "{base}#{name}".format(base=full_name_base_template, name=item["selector"]) - py_path = allured_testdir.testdir.makefile(".json", json.dumps(plan_json)) + + testplan = {"tests": planned_tests} + py_path = allured_testdir.testdir.makefile(".json", json.dumps(testplan)) os.environ["AS_TESTPLAN_PATH"] = py_path.strpath else: os.environ.pop("AS_TESTPLAN_PATH", None)