[TIP] Mocking sys.exit() and replacing it back?
Jorge Vargas
jorge.vargas at gmail.com
Thu Aug 5 20:34:12 PDT 2010
Hello,
Doing this seems really simple. All we need is something like
def mock_exit(exit_status):
return exit_status
class RunCommand(TestCase):
def setUp(self):
#we setup a fake sys.exit() to allow tests to continue
sys.exit = mock_exit
However I have two questions.
1- do I need a tearDown that will replace sys.exit with the original
function?
2- if so which is the best way to do this? store it in self.orig_exit ?
Or the test collector is smart enough to know it has to wipe out and
reimport everything on each testcase ?
In case someone asks this is with unittest2.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20100805/9d83ea10/attachment.htm>
More information about the testing-in-python
mailing list