def f1():
return 10, True
def f2():
num, stat = f1()
return 2*num, stat
Come si usa biblioteca finta di pitone per rattoppare f1()
e restituire un risultato personalizzato in modo ho potuto testare f2()
?Python cerotto finto una funzione all'interno di un'altra funzione
Modificato: C'è qualcosa che non va nel mio test? Questo non sembra funzionare, tutti i test non sono riusciti con AssertionError
from foo.bar import f2
from mock import patch
class MyTest(TestCase):
def test_f2_1(self):
with patch('project.module.f1') as some_func:
some_func.return_value = (20, False)
num, stat = f2()
self.assertEqual((num, stat), (40, False))
@patch('project.module.f1')
def test_f2_2(self, some_func):
some_func.return_value = (20, False)
num, stat = f2()
self.assertEqual((num, stat), (40, False))
Grazie per aver consigliato il collegamento http://bhfsteve.blogspot.nl relativo alle patch e agli stili di importazione. Questo ha risolto uno dei miei problemi. – HeyWatchThis