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
3 changes: 3 additions & 0 deletions allure-pytest/src/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ def pytest_runtest_makereport(self, item, call):
test_result.statusDetails = status_details

if self.config.option.attach_capture:
if test_result.status == Status.PASSED and not self.config.option.attach_capture_passed:
return

if report.caplog:
self.attach_data(report.caplog, "log", AttachmentType.TEXT, None)
if report.capstdout:
Expand Down
4 changes: 4 additions & 0 deletions allure-pytest/src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def pytest_addoption(parser):
dest="attach_capture",
help="Do not attach pytest captured logging/stdout/stderr to report")

parser.getgroup("reporting").addoption('--allure-no-capture-passed',
action="store_false",
dest="attach_capture_passed",
help="Do not attach pytest captured logging/stdout/stderr to passed report")
parser.getgroup("reporting").addoption('--inversion',
action="store",
dest="inversion",
Expand Down
44 changes: 44 additions & 0 deletions allure-pytest/test/acceptance/capture/capture_attach_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,47 @@ def test_capture_disabled(allured_testdir):
assert_that(allured_testdir.allure_report,
has_property("attachments", empty())
)


def test_capture_passed_disabled_for_successful(allured_testdir):
"""
>>> import logging
>>> logger = logging.getLogger(__name__)

>>> def test_capture_passed_disabled_example():
... logger.info("Start logging")
... print ("Start printing")

"""

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

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


def test_capture_passed_disabled_for_unsuccessful(allured_testdir):
"""
>>> import logging
>>> logger = logging.getLogger(__name__)

>>> def test_capture_passed_disabled_example():
... logger.info("Start logging")
... print ("Start printing")
... assert False

"""

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

assert_that(allured_testdir.allure_report,
has_property("attachments",
all_of(
is_(has_value(contains_string("Start logging"))),
is_(has_value(contains_string("Start printing")))
)
)
)