Skip to content

Instantly share code, notes, and snippets.

Embed
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.
# https://github.com/simon-weber/python-libfaketime
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.
"""
try:
import nose_cprofile
except ImportError:
return
profile_plugins = [p for p in nose_config.plugins.plugins if isinstance(p, nose_cprofile.Profile)]
if not profile_plugins:
return
assert len(profile_plugins) == 1
plugin = profile_plugins[0]
if plugin.enabled:
profiler = plugin.prof
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
You can’t perform that action at this time.