Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion allure-behave/tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
envlist =
py{36,37}
static_check
static-check

[testenv]
passenv = HOME
Expand Down
20 changes: 10 additions & 10 deletions allure-pytest/src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from allure_commons.logger import AllureFileLogger


from allure_pytest.utils import allure_label, allure_labels
from allure_pytest.utils import allure_label, allure_labels, allure_full_name
from allure_pytest.helper import AllureTestHelper
from allure_pytest.listener import AllureListener

Expand Down Expand Up @@ -148,18 +148,18 @@ def select_by_labels(items, config):


def select_by_testcase(items):
ids = []
plan = []
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])
if file_path:
with open(file_path, 'r') as plan_file:
plan = json.load(plan_file)

return filter(lambda item: ids & set(allure_label(item, LabelType.ID)) if ids else True, items)
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


def pytest_collection_modifyitems(items, config):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,62 @@
import pytest
import json
import os
from hamcrest import assert_that, only_contains, any_of, ends_with
from hamcrest import assert_that, contains_inanyorder, ends_with


@pytest.mark.parametrize("strategy", ["env_string", "env_path"])
@pytest.mark.parametrize(
["ids", "expected_tests"],
["plan_json", "expected_tests"],
[
# by ids only
(
[{"id": 1}, {"id": 2}],
["test_number_one", "test_number_two"]
),

# by ids for multiply decorated test
(
[{"id": 1}, {"id": 3}, {"id": 4}],
["test_number_one", "test_number_three"]
),

# by wrong id
(
[{"id": 1234}],
[]
),

# by selectors only
(
[{"selector": "test_number_one"}, {"selector": "test_number_three"}],
["test_number_one", "test_number_three"]
),

# by selector for not decorated with id test
(
[{"selector": "test_without_number"}],
["test_without_number"]
),

# by id and selector for same test
(
[{"id": 2, "selector": "test_number_two"}],
["test_number_two"]
),

# by wrong selector
(
[{"selector": "test_without_never"}],
[]
),

# without plan
(
None,
["test_number_one", "test_number_two", "test_number_three", "test_without_number"]
),
]
)
def test_select_by_testcase_id_test(strategy, ids, expected_tests, allured_testdir):
def test_select_by_testcase_id_test(plan_json, expected_tests, allured_testdir, request):
"""
>>> import allure

Expand All @@ -42,21 +76,24 @@ def test_select_by_testcase_id_test(strategy, ids, expected_tests, allured_testd
>>> def test_without_number():
... pass
"""
allured_testdir.parse_docstring_source()

if strategy == "env_path" and ids:
py_path = allured_testdir.testdir.makefile(".json", json.dumps(ids))
root_dir = request.config.rootdir.strpath
test_dir = allured_testdir.testdir.tmpdir.strpath.replace(root_dir, "")
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 "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))
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:
os.environ.pop("AS_TESTPLAN_PATH", None)
os.environ.pop("AS_TESTPLAN_IDS", None)

allured_testdir.parse_docstring_source()
allured_testdir.run_with_allure()
test_cases = [test_case["fullName"] for test_case in allured_testdir.allure_report.test_cases]
assert_that(test_cases, only_contains(
any_of(
*[ends_with(name) for name in expected_tests]
)
))

executed_full_names = [test_case["fullName"] for test_case in allured_testdir.allure_report.test_cases]

assert_that(executed_full_names, contains_inanyorder(*[ends_with(name) for name in expected_tests]))
2 changes: 1 addition & 1 deletion allure-pytest/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ envlist =
py{36,37}
xdist
integration
static_check
static-check


[testenv]
Expand Down
2 changes: 1 addition & 1 deletion allure-python-commons/src/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __is(kind, t):
return kind in [v for k, v in t.__dict__.items() if not k.startswith('__')]


def parse_tag(tag, *, issue_pattern=None, link_pattern=None):
def parse_tag(tag, issue_pattern=None, link_pattern=None):
"""
>>> parse_tag("blocker")
Label(name='severity', value='blocker')
Expand Down
2 changes: 1 addition & 1 deletion allure-python-commons/tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
envlist=
py{36,37}
static_check
static-check


[testenv]
Expand Down
2 changes: 1 addition & 1 deletion allure-robotframework/tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
envlist=
py{36,37}
static_check
static-check


[testenv]
Expand Down