Saturday 15 March 2014

python - Calling origin function in mock.patch -



python - Calling origin function in mock.patch -

i have function utilize shutil.move move multiple files location. when fails, want phone call cleaning code. wrote automated test, have 5 files, want raise exception on 3rd phone call of shutil.move , check if cleaning done. naive thought was:

def test_failed_processing_clean_ups_database(self): class localcounter: call_counter = 0 def code_breaker(src, dst): localcounter.call_counter += 1 if localcounter.call_counter > 2: raise codebreakerexception('code made booom!') shutil.move(src, dst) mock.patch('dashboard.tasks.shutil.move') mck: mck.side_effect = code_breaker my_processing_code_that_uses_shutil_move() # check if clean...

but not work. shutil.move patched in code_breaker function too, gets stacked. need phone call original shutil.move because other things depends on this. suggestions how this? thanks!

python mocking

No comments:

Post a Comment