Claude Discovery

← All discoveries

Vivid, blurred close-up of colorful code on a screen, representing web development and programming.
Photo by Markus Spiske on Pexels
library

One Decorator, Two Jobs: Wrapture Traces and Fakes Functions at Once

2026-09-01 ยท source:

Wrapture is a Python library by wrapt author Graham Dumpleton that wraps any function or method so calls can be traced and, in the same wrap, overridden to return test doubles.

What it is

Wrapture is a new library from Graham Dumpleton, the developer behind wrapt, mod_wsgi, and New Relic's Python agent, extending wrapt's monkeypatching approach to cover testing and tracing together.

What it does

It lets a developer wrap any function or method so that every call can be traced and, independently or simultaneously, overridden to return a different value, combining what would otherwise be separate tracing and mocking layers into one mechanism.

Why it matters

Instead of maintaining a tracing decorator and a separate mocking library that both patch the same function, unlike bolting `unittest.mock` and a tracer on top of each other, Wrapture handles both from the same wrap point, which should mean fewer surprises when they interact.

How to use it

Install Wrapture from PyPI and read the full documentation for wrap-and-override patterns applied to existing functions or methods.

Go to source →
pythontestingtracingmonkeypatching