Skip to content

Commit

Permalink
Merge branch 'main' into skip-remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyu-ms committed Dec 20, 2023
2 parents 6cf423c + 479dfc7 commit 2f0fe1a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/newsfragments/2811_new.empty_report.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip exporters invocation when report is empty.
6 changes: 6 additions & 0 deletions testplan/common/report/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ def flattened_entries(self, depth):
"""
return [(depth, entry) for entry in self]

def is_empty(self) -> bool:
"""
Check report is empty or not.
"""
return len(self.entries) == len(self.logs) == 0

@property
def hash(self):
"""Return a hash of all entries in this report."""
Expand Down
8 changes: 6 additions & 2 deletions testplan/runnable/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,8 @@ def _pre_exporters(self):
)

def _invoke_exporters(self) -> None:
# Add this logic into a ReportExporter(Runnable)
# that will return a result containing errors
if self._result.test_report.is_empty(): # skip empty report
return

if hasattr(self._result.test_report, "bubble_up_attachments"):
self._result.test_report.bubble_up_attachments()
Expand All @@ -1280,6 +1280,10 @@ def _post_exporters(self):
report_urls = []
report_opened = False

if self._result.test_report.is_empty(): # skip empty report
self.logger.warning("Empty report, nothing to be exported!")
return

for result in self._result.exporter_results:
report_url = getattr(result.exporter, "report_url", None)
if report_url:
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/testplan/report/testing/test_empty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from unittest.mock import patch


def test_empty_testplan(mockplan):
with patch("logging.Logger.warning") as mock_logger:
result = mockplan.run()
mock_logger.assert_called_with("Empty report, nothing to be exported!")
report = result.report
assert report.is_empty() is True

0 comments on commit 2f0fe1a

Please sign in to comment.