Skip to content

Instantly share code, notes, and snippets.

@matthewlmcclure
Created July 31, 2013 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewlmcclure/6124117 to your computer and use it in GitHub Desktop.
Save matthewlmcclure/6124117 to your computer and use it in GitHub Desktop.
Log information about the objects replaced by Python Mock, patch. Combine with similar logging in your application to debug patching.
--- mock.py~ 2013-07-31 13:20:48.000000000 -0400
+++ mock.py 2013-07-31 13:19:57.000000000 -0400
@@ -32,9 +32,12 @@
__version__ = '0.8.0'
+import logging
import pprint
import sys
+logger = logging.getLogger(__name__)
+
try:
import inspect
except ImportError:
@@ -1112,7 +1115,8 @@
try:
return getattr(thing, comp)
except AttributeError:
- __import__(import_path)
+ thing = __import__(import_path)
+ logger.debug('thing: %r', thing)
return getattr(thing, comp)
@@ -1120,10 +1124,12 @@
components = target.split('.')
import_path = components.pop(0)
thing = __import__(import_path)
+ logger.debug('thing: %r', thing)
for comp in components:
import_path += ".%s" % comp
thing = _dot_lookup(thing, comp, import_path)
+ logger.debug('thing: %r', thing)
return thing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment