def test_run_coveralls_wear_error_once(self): """On Coveralls.wear() error we should try another `service_name`.""" url = "https://coveralls.io/jobs/1234" side_effect = ( CoverallsException("Error"), { "message": "Job ##12.34", "url": url }, ) with patch_coveralls_wear() as m_wear, patch_log() as m_log: m_wear.side_effect = side_effect entrypoint.run_coveralls(repo_token="TOKEN") assert m_wear.call_args_list == [mock.call(), mock.call()] assert m_log.method_calls == [ mock.call.info( "Trying submitting coverage with service_name: github..."), mock.call.debug( "Patching os.environ with: " "{'COVERALLS_REPO_TOKEN': 'TOKEN', 'COVERALLS_PARALLEL': ''}"), mock.call.warning( "Failed submitting coverage with service_name: github"), mock.call.warning(side_effect[0]), mock.call.info( "Trying submitting coverage with service_name: github-actions..." ), mock.call.debug( "Patching os.environ with: " "{'COVERALLS_REPO_TOKEN': 'TOKEN', 'COVERALLS_PARALLEL': ''}"), mock.call.debug(side_effect[1]), mock.call.info(url), ]
def test_status_code_422(self): """ Makes sure the coveralls package retries on "422 Unprocessable Entry" error rather than crashing while trying to access the `service_job_id` key, refs: https://github.com/coveralls-clients/coveralls-python/pull/241/files#r532248047 """ status_code = 422 with patch_requests_post(status_code=status_code) as m_post, pytest.raises( SystemExit, match=f"{entrypoint.ExitCode.FAILURE}" ), patch_log() as m_log: entrypoint.run_coveralls(repo_token="TOKEN") # coveralls package will retry once per service we call it with assert m_post.call_count == 4 assert m_log.error.call_args_list == [ mock.call("Failed to submit coverage", exc_info=None) ] assert m_log.warning.call_args_list == [ mock.call( "Failed submitting coverage with service_name: github", exc_info=CoverallsException( "Could not submit coverage: 422 Client Error: None for url: None" ), ), mock.call( "Failed submitting coverage with service_name: github-actions", exc_info=CoverallsException( "Could not submit coverage: 422 Client Error: None for url: None" ), ), ]
def test_run_coveralls_wear_error_twice(self): """Exits with error code if Coveralls.wear() fails twice.""" side_effect = ( CoverallsException("Error 1"), CoverallsException("Error 2"), ) with patch_coveralls_wear() as m_wear, pytest.raises( SystemExit) as ex_info: m_wear.side_effect = side_effect entrypoint.run_coveralls(repo_token="TOKEN") assert ex_info.value.args == (entrypoint.ExitCode.FAILURE, )
def test_run_coveralls_github_token(self): """Simple case when Coveralls.wear() returns some results.""" url = "https://coveralls.io/jobs/1234" with patch_coveralls_wear() as m_wear, patch_log() as m_log: m_wear.return_value = { "message": "Job ##12.34", "url": url, } entrypoint.run_coveralls(repo_token="TOKEN") assert m_wear.call_args_list == [mock.call()] assert m_log.method_calls == [ mock.call.info( "Trying submitting coverage with service_name: github..."), mock.call.debug( "Patching os.environ with: " "{'COVERALLS_REPO_TOKEN': 'TOKEN', 'COVERALLS_PARALLEL': ''}"), mock.call.debug(m_wear.return_value), mock.call.info(url), ]