Skip to content

Commit

Permalink
do not attach empty logs (via allure-framework#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
sseliverstov authored Apr 30, 2019
1 parent 6ebccee commit b317e4d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
10 changes: 6 additions & 4 deletions allure-pytest/src/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@ def pytest_runtest_makereport(self, item, call):
test_result.statusDetails = status_details

if self.config.option.attach_capture:
# Capture at teardown contains data from whole test (setup, call, teardown)
self.attach_data(report.caplog, "log", AttachmentType.TEXT, None)
self.attach_data(report.capstdout, "stdout", AttachmentType.TEXT, None)
self.attach_data(report.capstderr, "stderr", AttachmentType.TEXT, None)
if report.caplog:
self.attach_data(report.caplog, "log", AttachmentType.TEXT, None)
if report.capstdout:
self.attach_data(report.capstdout, "stdout", AttachmentType.TEXT, None)
if report.capstderr:
self.attach_data(report.capstderr, "stderr", AttachmentType.TEXT, None)

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_logfinish(self, nodeid, location):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import pytest
from hamcrest import assert_that
from hamcrest import all_of
from hamcrest import has_property, has_value
from hamcrest import contains_string
from allure_commons_test.report import has_test_case
from allure_commons_test.result import has_attachment


@pytest.mark.parametrize("param", ["first", "second"])
def test_parametrized_attachment(executed_docstring_source, param):
"""
>>> import pytest
>>> import allure
>>> @pytest.mark.parametrize("param", ["first", "second"])
... def test_parametrized_attachment_example(param):
... assert param
... allure.attach(param)
"""

assert_that(executed_docstring_source.allure_report,
has_test_case("test_parametrized_attachment_example[{param}]".format(param=param),
has_attachment()
)
)
all_of(
has_test_case("test_parametrized_attachment_example[{param}]".format(param=param)),
has_property("attachments",
has_value(contains_string(param))
)
))
27 changes: 27 additions & 0 deletions allure-pytest/test/acceptance/capture/capture_attach_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ def test_capture_stdout(allured_testdir, capture):
)


@pytest.mark.parametrize("capture", ["sys", "fd"])
def test_capture_empty_stdout(allured_testdir, capture):
"""
>>> import pytest
>>> import allure
>>> @pytest.fixture
... def fixture(request):
... def finalizer():
... pass
... request.addfinalizer(finalizer)
>>> def test_capture_stdout_example(fixture):
... with allure.step("Step"):
... pass
"""

allured_testdir.parse_docstring_source()
allured_testdir.run_with_allure("--capture={capture}".format(capture=capture))

assert_that(allured_testdir.allure_report,
has_property("attachments", empty())
)


@pytest.mark.parametrize("logging", [True, False])
def test_capture_log(allured_testdir, logging):
"""
Expand Down Expand Up @@ -93,7 +118,9 @@ def test_capture_disabled(allured_testdir):
"""

allured_testdir.parse_docstring_source()
allured_testdir.run_with_allure("--log-cli-level=INFO", "--allure-no-capture")

assert_that(allured_testdir.allure_report,
has_property("attachments", empty())
)

0 comments on commit b317e4d

Please sign in to comment.