This is the kind of thing that would ideally be cleaned up in a function registered immediately after the monkeypatch is made.  Otherwise, if this test fails, the state is never cleaned back up and subsequent tests may fail because of the dirty module.  Could you leverage Rick's recent changes to register a cleanup function instead of this?