Skip to content

Commit bb1775b

Browse files
authored
do not attach empty logs (via #373)
1 parent 070fdcc commit bb1775b

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

allure-pytest/src/listener.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,12 @@ def pytest_runtest_makereport(self, item, call):
194194
test_result.statusDetails = status_details
195195

196196
if self.config.option.attach_capture:
197-
# Capture at teardown contains data from whole test (setup, call, teardown)
198-
self.attach_data(report.caplog, "log", AttachmentType.TEXT, None)
199-
self.attach_data(report.capstdout, "stdout", AttachmentType.TEXT, None)
200-
self.attach_data(report.capstderr, "stderr", AttachmentType.TEXT, None)
197+
if report.caplog:
198+
self.attach_data(report.caplog, "log", AttachmentType.TEXT, None)
199+
if report.capstdout:
200+
self.attach_data(report.capstdout, "stdout", AttachmentType.TEXT, None)
201+
if report.capstderr:
202+
self.attach_data(report.capstderr, "stderr", AttachmentType.TEXT, None)
201203

202204
@pytest.hookimpl(hookwrapper=True)
203205
def pytest_runtest_logfinish(self, nodeid, location):
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import pytest
22
from hamcrest import assert_that
3+
from hamcrest import all_of
4+
from hamcrest import has_property, has_value
5+
from hamcrest import contains_string
36
from allure_commons_test.report import has_test_case
4-
from allure_commons_test.result import has_attachment
57

68

79
@pytest.mark.parametrize("param", ["first", "second"])
810
def test_parametrized_attachment(executed_docstring_source, param):
911
"""
1012
>>> import pytest
13+
>>> import allure
1114
1215
>>> @pytest.mark.parametrize("param", ["first", "second"])
1316
... def test_parametrized_attachment_example(param):
14-
... assert param
17+
... allure.attach(param)
1518
"""
1619

1720
assert_that(executed_docstring_source.allure_report,
18-
has_test_case("test_parametrized_attachment_example[{param}]".format(param=param),
19-
has_attachment()
20-
)
21-
)
21+
all_of(
22+
has_test_case("test_parametrized_attachment_example[{param}]".format(param=param)),
23+
has_property("attachments",
24+
has_value(contains_string(param))
25+
)
26+
))

allure-pytest/test/acceptance/capture/capture_attach_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ def test_capture_stdout(allured_testdir, capture):
4141
)
4242

4343

44+
@pytest.mark.parametrize("capture", ["sys", "fd"])
45+
def test_capture_empty_stdout(allured_testdir, capture):
46+
"""
47+
>>> import pytest
48+
>>> import allure
49+
50+
>>> @pytest.fixture
51+
... def fixture(request):
52+
... def finalizer():
53+
... pass
54+
... request.addfinalizer(finalizer)
55+
56+
>>> def test_capture_stdout_example(fixture):
57+
... with allure.step("Step"):
58+
... pass
59+
"""
60+
61+
allured_testdir.parse_docstring_source()
62+
allured_testdir.run_with_allure("--capture={capture}".format(capture=capture))
63+
64+
assert_that(allured_testdir.allure_report,
65+
has_property("attachments", empty())
66+
)
67+
68+
4469
@pytest.mark.parametrize("logging", [True, False])
4570
def test_capture_log(allured_testdir, logging):
4671
"""
@@ -93,7 +118,9 @@ def test_capture_disabled(allured_testdir):
93118
94119
"""
95120

121+
allured_testdir.parse_docstring_source()
96122
allured_testdir.run_with_allure("--log-cli-level=INFO", "--allure-no-capture")
123+
97124
assert_that(allured_testdir.allure_report,
98125
has_property("attachments", empty())
99126
)

0 commit comments

Comments
 (0)