0

I am developing unit test for code that use Google oauth2client.tools run_flow(). The problem is, this function will call Python webbrowser.open(), that will eventually (cmiiw), exit itself by calling sys.exit(). Therefore, even if I halt the code execution using threading.Event.wait(), it will eventually terminate, without continuing the rest of the unit testing code.

I have read this SO answer that previously was my problem, but now I still faced with this webbrowser.open() issue.

Any idea on how to solve this?

Community
  • 1
  • 1
swdev
  • 4,997
  • 8
  • 64
  • 106
  • 1
    You probably want to mock `webbrowser.open` so that it doesn't actually run. (You might even want to mock `run_flow`, if it isn't essential to your test that it actually be called.) It's hard to be more specific without seeing the code you want to test and knowing what exactly you are testing. – chepner Aug 07 '15 at 14:01
  • 1
    try mock `sys.exit` whit some other function? – luoluo Aug 07 '15 at 14:27
  • I am pretty new to unit testing: especially with mock. But, I really want to get the result of `webbrowser.open()' (that is, creating Picasa token). So I don't think that is a viable option though. – swdev Aug 07 '15 at 14:44

0 Answers0