Thanks to visit codestin.com
Credit goes to GitHub.com

Skip to content
Open
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
22 changes: 22 additions & 0 deletions allure-pytest/src/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,28 @@ def pytest_runtest_makereport(self, item, call):
if report.capstderr:
self.attach_data(report.capstderr, "stderr", AttachmentType.TEXT, None)

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_logreport(self, report):
yield
if hasattr(report, "context"):
item_uuid = self._cache.get(report.nodeid)
step_uuid = uuid4()
step = TestStepResult(name=report.context.msg or report.head_line, start=report.start)
if report.longrepr:
status_details = StatusDetails(
message=report.longrepr.reprcrash.message,
trace=report.longreprtext
)
else:
status_details = None
self.allure_logger.start_step(item_uuid, step_uuid, step)
self.allure_logger.stop_step(
step_uuid,
stop=report.stop,
status=report.outcome,
statusDetails=status_details
)

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_logfinish(self, nodeid, location):
yield
Expand Down
65 changes: 65 additions & 0 deletions tests/allure_pytest/acceptance/step/subtest_as_step_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from hamcrest import assert_that
from tests.allure_pytest.pytest_runner import AllurePytestRunner

from allure_commons_test.report import has_test_case
from allure_commons_test.result import has_step
from allure_commons_test.result import with_status
from allure_commons_test.result import with_message_contains
from allure_commons_test.result import has_status_details


def test_with_subtest(allure_pytest_runner: AllurePytestRunner):
"""
>>> import allure
>>> import pytest
>>> @pytest.mark.skipif("pytest.__version__[0] < '9'")
>>> def test_with_subtest(subtests):
... with subtests.test(msg='Some failed subtest'):
... assert False, 'Some error'
... with allure.step('Next step'):
... pass
"""

allure_results = allure_pytest_runner.run_docstring()

assert_that(
allure_results,
has_test_case(
"test_with_subtest",
has_step(
"Some failed subtest",
with_status("failed"),
has_status_details(
with_message_contains("Some error")
)
),
has_step(
"Next step",
with_status("passed")
),
with_status("failed")
)
)


def test_with_subtest_without_msg(allure_pytest_runner: AllurePytestRunner):
"""
>>> import allure
>>> import pytest
>>> @pytest.mark.skipif("pytest.__version__[0] < '9'")
>>> def test_with_subtest_without_msg(subtests):
... with subtests.test():
... pass
"""

allure_results = allure_pytest_runner.run_docstring()

assert_that(
allure_results,
has_test_case(
"test_with_subtest_without_msg",
has_step(
"test_with_subtest_without_msg (<subtest>)",
),
)
)
Loading