New release of globalsub is out

Globalsub is a mechanism to allow you easily replace an object throughout your interpreter.  This is normally done to make it easier to test.  You can stub out objects which have side effects for most of your tests and just test those functions in carefully isolated environments.  It comes from the Mocker codebase originally, but has grown somewhat more involved in what it does lately.

This release adds the ability to subs out ints, long, str and unicode instances.  This is most useful for rewriting constants such as Django settings.py values so that your test suite can run with its side effects localized to a temporary directory.

globalsub.subs( settings.CONFIG_SERVER, 'http://testserver/')
...
globalsub.restore( settings.CONFIG_SERVER )

Anything that references CONFIG_SERVER (even if it did from settings import CONFIG_SERVER) will be updated to point to your new value.  Obviously this does *not* cause strings that were built up *from* the CONFIG_SERVER variable on import to change, but you can subs those as well if you need to.

pip install globalsub

Comments

Comments are closed.

Pingbacks

Pingbacks are closed.