Skip to content

Instantly share code, notes, and snippets.

@rectangletangle
rectangletangle / gist:0a0d5a2e84dd3178d348
Last active January 29, 2022 17:32
Python 3 Monkeypatch Context Manager
""" This is a convenient way to monkeypatch a method or attribute of a Python
object. This is great for situations where you want to modify a global
object within a limited scope, i.e., your typical class or module when
testing. This was tested and works with Python 2.7 and 3.4. """
import contextlib
@contextlib.contextmanager
def monkeypatched(object, name, patch):
""" Temporarily monkeypatches an object. """
@RyanGWU82
RyanGWU82 / capture-boto3.py
Created July 15, 2015 18:54
Do you use boto3 or botocore? Want to capture and inspect your AWS API traffic? This script will send all AWS API traffic to a Runscope bucket for analysis and debugging.
# Do you use boto3 or botocore? Want to capture and inspect your AWS API
# traffic? This script will send all AWS API traffic to a Runscope bucket for
# analysis and debugging.
#
# Instructions:
# 1. Sign up for an account at https://www.runscope.com if you don't already
# have one.
# 2. Your account will have a single bucket. Get the Bucket Key from Runscope's
# Traffic Inspector tab; paste that into the RUNSCOPE_BUCKET_KEY constant.
# 3. Go to https://www.runscope.com/applications and create a new application.