Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9812eb9

Browse files
author
Siddharta Govindaraj
committed
Using mock.patch as a context manager
1 parent b66df71 commit 9812eb9

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

stock_alerter/tests/test_action.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77
class PrintActionTest(unittest.TestCase):
88
def test_executing_action_prints_message(self):
9-
patcher = mock.patch('builtins.print')
10-
mock_print = patcher.start()
11-
try:
9+
with mock.patch('builtins.print') as mock_print:
1210
action = PrintAction()
1311
action.execute("GOOG > $10")
1412
mock_print.assert_called_with("GOOG > $10")
15-
finally:
16-
patcher.stop()

0 commit comments

Comments
 (0)