Last active
October 26, 2018 14:21
-
-
Save johnmanjiro13/129670da683b54c5c537ed4e0f7a3150 to your computer and use it in GitHub Desktop.
test try_except_deco
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.mock import MagicMock | |
from try_except_decorator import try_except | |
def test_valid(): | |
""" | |
例外が起きなかった場合にデコレートされた関数の戻り値が返ること | |
""" | |
mock_func = MagicMock(return_value='correct') # こんな感じで定義時に与えることもできます | |
result = try_except(exreturn_value='excepted')(mock_func)() # 3回の呼び出し | |
assert result == 'correct', "デコレートされた関数の戻り値が返る" | |
def test_invalid(): | |
""" | |
例外が起きた時にデコレータに渡した引数が返ること | |
""" | |
mock_func = MagicMock(return_value='correct') | |
mock_func.side_effect = Exception() # 例外が起きるようにする | |
result = try_except(exreturn_value='excepted')(mock_func)() | |
assert result == 'excepted', "デコレータに渡した引数が返る" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment