diff --git a/tests/conftest.py b/tests/conftest.py index 06a8990..1c3eb63 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,7 @@ import pytest_codecov.codecov import pytest_codecov.git +from coverage.misc import CoverageException from importlib import reload pytest_plugins = 'pytester' @@ -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' @@ -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. diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 011fbcd..291fa91 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -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