Skip to content

Commit

Permalink
add flag that allows not to attach logs for passed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
efpato committed Mar 19, 2021
1 parent c217262 commit 0d239c6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
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
5 changes: 5 additions & 0 deletions allure-pytest/src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ 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")

def label_type(type_name, legal_values=set()):
def a_label_type(string):
atoms = set(string.split(','))
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")))
)
)
)

0 comments on commit 0d239c6

Please sign in to comment.