Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chfw/961dfc279d56a34d33eca8bbe9f168e7 to your computer and use it in GitHub Desktop.
Save chfw/961dfc279d56a34d33eca8bbe9f168e7 to your computer and use it in GitHub Desktop.
it's been challenging to do that simple task, which is put a print statement in the emptied module file. when it comes to testing,
the first block is to how to test the output? one solution is to mock sys.stdout, the other is to wrap print in a function and patch it.
the second block is the module is already loaded and won't be loaded again. Hence you need to reload it. for reload, py2 and py3 had a
difference in where the reload comes from. here is the code to get around.
try:
reload
except NameError:
from imp import reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment