pythonmockingnose

How to get around "sys.exit()" in python nosetest?


It seems that python nosetest will quit when encountered sys.exit(), and mocking of this builtin doesn't work.


Solution

  • You can try catching the SystemExit exception. It is raised when someone calls sys.exit().

    with self.assertRaises(SystemExit):
      myFunctionThatSometimesCallsSysExit()