Skip to content

Instantly share code, notes, and snippets.

Created June 15, 2017 22:06
What would you like to do?
disabling profiling around python-libfaketime example
# An example to disable profiling when faking time with python-libfaketime.
# Call this once from setup_package or a similar hook at the start of the test run.
def disable_profiling_around_libfaketime(nose_config):
libfaketime's interception of time system calls will break profilers.
If we detect that we're running under a profiler, we set up libfaketime callbacks to
temporarily disable profiling when we're faking the time.
import nose_cprofile
except ImportError:
profile_plugins = [p for p in nose_config.plugins.plugins if isinstance(p, nose_cprofile.Profile)]
if not profile_plugins:
assert len(profile_plugins) == 1
plugin = profile_plugins[0]
if plugin.enabled:
profiler =
libfaketime.begin_callback = lambda _: profiler.disable()
libfaketime.end_callback = lambda _: profiler.enable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment