Код: Выделить всё
def method_under_test():
r = requests.post("http://localhost/post")
print r.ok # prints ""
if r.ok:
return StartResult()
else:
raise Exception()
class MethodUnderTestTest(TestCase):
def test_method_under_test(self):
with patch('requests.post') as patched_post:
patched_post.return_value.ok = True
result = method_under_test()
self.assertEqual(type(result), StartResult,
"Failed to return a StartResult.")
Подробнее здесь: https://stackoverflow.com/questions/168 ... ython-mock