Last active
August 29, 2015 14:16
-
-
Save stupidbodo/22d9e831f0450868b138 to your computer and use it in GitHub Desktop.
Python Testing Example - How to mock property for testing
This file contains hidden or 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
import unittest | |
import mock | |
class Trainer(object): | |
@property | |
def column_names(self): | |
return ["one", "two"] | |
def ret_column_names(self): | |
return self.column_names | |
class Tester(unittest.TestCase): | |
@mock.patch.object(Trainer, "column_names") | |
def test_ret_column_names(self, mock_column_names): | |
trainer = Trainer | |
columns = ['three', 'four'] | |
mock_column_names.__get__ = mock.Mock(return_value=columns) | |
self.assertEquals(trainer.ret_column_names(), columns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment