How to prevent unit testing from exiting when calling webbrowser.open()?
Asked Answered
N

0

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?

Nalepka answered 7/8, 2015 at 13:50 Comment(3)
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.Albumose
try mock sys.exit whit some other function?Jorgenson
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.Nalepka

© 2022 - 2024 — McMap. All rights reserved.