Skip to content

Commit

Permalink
Adds test case for report generation failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Daverball committed Aug 21, 2024
1 parent 6c068d8 commit 0f2f0f1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest_codecov.codecov
import pytest_codecov.git

from coverage.misc import CoverageException
from importlib import reload

pytest_plugins = 'pytester'
Expand Down Expand Up @@ -113,13 +114,14 @@ class DummyUploader:
# more exhaustively.

def __init__(self, slug, **kwargs):
pass
self.fail_report_generation = False

def write_network_files(self, files):
pass

def add_coverage_report(self, cov, **kwargs):
pass
if self.fail_report_generation:
raise CoverageException('test exception')

def get_payload(self):
return 'stub'
Expand All @@ -131,12 +133,24 @@ def upload(self):
pass


class DummyUploaderFactory:

fail_report_generation = False

def __call__(self, slug, **kwargs):
inst = DummyUploader(slug, **kwargs)
inst.fail_report_generation = self.fail_report_generation
return inst


@pytest.fixture
def dummy_uploader(monkeypatch):
factory = DummyUploaderFactory()
monkeypatch.setattr(
'pytest_codecov.codecov.CodecovUploader',
DummyUploader
factory
)
return factory


# NOTE: Ensure modules are reloaded when coverage.py is looking.
Expand Down
19 changes: 19 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,22 @@ def test_upload_report(pytester, dummy_reporter, dummy_uploader,
'Branch: master\n'
'Commit: deadbeef\n'
) in dummy_reporter.text


def test_upload_report_generation_failure(
pytester, dummy_reporter, dummy_uploader,
dummy_cov, no_gitpython
):
dummy_uploader.fail_report_generation = True
config = pytester.parseconfig(
'--codecov',
'--codecov-token=12345678-1234-1234-1234-1234567890ab',
'--codecov-slug=foo/bar',
'--codecov-branch=master',
'--codecov-commit=deadbeef'
)
plugin = CodecovPlugin()
plugin.upload_report(dummy_reporter, config, dummy_cov)
assert (
'ERROR: Failed to generate XML report: test exception'
) in dummy_reporter.text

0 comments on commit 0f2f0f1

Please sign in to comment.