You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
add_hookcall_monitoring undo breaks when called out of LIFO order #815
🤖 Written by Claude Opus 5.5 via Claude Code for the pluggy maintainers; I prompted it, it did the work, I read it.
add_hookcall_monitoring() returns an undo that restores the _inner_hookexec it saw at add time (src/pluggy/_manager.py, undo() sets self._inner_hookexec = oldcall). So undo only works in strict LIFO order:
undoing an older monitor also removes every monitor added after it
a later undo can bring back a monitor that was already removed
This applies to enable_tracing() too, since it is built on add_hookcall_monitoring().
The same thing happens on current main. pytest's own uses (--debug, pytester's HookRecorder) undo in LIFO order, so as far as we know nobody has hit this in practice.
Possible fix: keep the active (before, after) pairs in a list on the PluginManager. Each undo removes its own entry by identity, which makes repeated undo harmless, and then rebuilds _inner_hookexec from the list. Calls already in flight keep the chain they started with.
Found while reviewing #814, which fixed this with a much larger change and was closed.
Activity