I'm pretty sure I've seen this, but I can't get the syntax right. I want to override a module "constant" during testing. I can write the code like this:
import mymodule
try:
hold = mymodule.FOO
mymodule.FOO = 'test value'
do_something()
finally:
mymodule.FOO = hold
it seems to me that there should be a way to do this with a "with" statement, something like:
with mymodule.FOO = 'test value':
do_something()
Is my mind deceiving me? Is there a simple syntax to do what I want?