Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Patching: Replacing a method call with another
- # module_A.py
- def original_func(arg_a,arg_b):
- # ...
- # module_B.py
- import module_A
- def func_under_test():
- # ...
- module_A.original_func(a,b)
- # Some code that depends on the behavior of the patched function
- # ...
- # my test code
- def alternative_func(arg_a,arg_b):
- # do something essential for the test
- def the_test():
- # patch the original_func with the alternative_func here
- func_under_test()
- # assertions
- module_A.original_func = alternative_func
- import module_a
- def the_test():
- orig_func = module_a.original_func
- module_a.original_func = alternative_func
- # do testing stuff
- # then restore original func for other tests
- module_a.original_func = orig_func
- original_func = alternative_func
Add Comment
Please, Sign In to add comment