Skip to content

Commit 0d239c6

Browse files
committed
add flag that allows not to attach logs for passed tests
1 parent c217262 commit 0d239c6

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

allure-pytest/src/listener.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ def pytest_runtest_makereport(self, item, call):
203203
test_result.statusDetails = status_details
204204

205205
if self.config.option.attach_capture:
206+
if test_result.status == Status.PASSED and not self.config.option.attach_capture_passed:
207+
return
208+
206209
if report.caplog:
207210
self.attach_data(report.caplog, "log", AttachmentType.TEXT, None)
208211
if report.capstdout:

allure-pytest/src/plugin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def pytest_addoption(parser):
3434
dest="attach_capture",
3535
help="Do not attach pytest captured logging/stdout/stderr to report")
3636

37+
parser.getgroup("reporting").addoption('--allure-no-capture-passed',
38+
action="store_false",
39+
dest="attach_capture_passed",
40+
help="Do not attach pytest captured logging/stdout/stderr to passed report")
41+
3742
def label_type(type_name, legal_values=set()):
3843
def a_label_type(string):
3944
atoms = set(string.split(','))

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,47 @@ def test_capture_disabled(allured_testdir):
124124
assert_that(allured_testdir.allure_report,
125125
has_property("attachments", empty())
126126
)
127+
128+
129+
def test_capture_passed_disabled_for_successful(allured_testdir):
130+
"""
131+
>>> import logging
132+
>>> logger = logging.getLogger(__name__)
133+
134+
>>> def test_capture_passed_disabled_example():
135+
... logger.info("Start logging")
136+
... print ("Start printing")
137+
138+
"""
139+
140+
allured_testdir.parse_docstring_source()
141+
allured_testdir.run_with_allure("--log-cli-level=INFO", "--allure-no-capture-passed")
142+
143+
assert_that(allured_testdir.allure_report,
144+
has_property("attachments", empty())
145+
)
146+
147+
148+
def test_capture_passed_disabled_for_unsuccessful(allured_testdir):
149+
"""
150+
>>> import logging
151+
>>> logger = logging.getLogger(__name__)
152+
153+
>>> def test_capture_passed_disabled_example():
154+
... logger.info("Start logging")
155+
... print ("Start printing")
156+
... assert False
157+
158+
"""
159+
160+
allured_testdir.parse_docstring_source()
161+
allured_testdir.run_with_allure("--log-cli-level=INFO", "--allure-no-capture-passed")
162+
163+
assert_that(allured_testdir.allure_report,
164+
has_property("attachments",
165+
all_of(
166+
is_(has_value(contains_string("Start logging"))),
167+
is_(has_value(contains_string("Start printing")))
168+
)
169+
)
170+
)

0 commit comments

Comments
 (0)