Last active
September 27, 2021 21:27
-
-
Save dmcnulla/ecec8fc96a2fd07082f240eeff6888d9 to your computer and use it in GitHub Desktop.
Reproduce call_args_list for multiple side_effects in python unittest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unittest import TestCase, mock | |
JIRA_URL = 'https://jira' | |
EXECUTOR = 'executedBy' | |
FAKE_USER = 'fake_user' | |
class JiraException(RuntimeError): | |
pass | |
class JiraConnection: | |
def update_test_run_result(self, case: dict) -> None: | |
try: | |
self._send_to_jira(body=case) | |
except JiraException: | |
case.pop(EXECUTOR) | |
self._send_to_jira(body=case) | |
def _send_to_jira(self, body: dict): | |
return 'xyz' | |
class TestUpdateTestRunResult(TestCase): | |
@mock.patch('test_multiple_side_effect.JiraConnection._send_to_jira', | |
side_effect=[JiraException, None]) | |
def test_update_test_run_executor_did_not_exist(self, mock_send_to_jira): | |
JiraConnection().update_test_run_result(case={EXECUTOR: FAKE_USER}) | |
self.assertEqual(mock_send_to_jira.call_args_list[0].kwargs["body"], {EXECUTOR: FAKE_USER}) | |
self.assertEqual(mock_send_to_jira.call_args_list[1].kwargs["body"], {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment