Issue 49 in pymox: pymox should support a context handler for verification

Skip to first unread message

Jul 30, 2012, 4:46:08 AM7/30/12
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 49 by pymox should support a context
handler for verification

[this is a feature request]

I recently wrote a small helper class to allow a context handlers to
provide verification. e.g.

def testFoo(self):
# set expectations
with Verification(self.mox):
# call code, assert results.

The implementation is simple:

class Verification(object):
def __init__(self, m):
self.m = m

def __enter__(self):

def __exit__(self, exc_type, exc_value, traceback):
if exc_type is None and exc_value is None and traceback is None:

I think that this should probably be a core part of mox, allowing one to

def testFoo(self):
with self.mox.Verification():
# …

To my eye, this nicely delineates the code under test from the setup code.

I've attached a sample implementation for discussion. Some points from

- I'm not sure what the minimum Python version of pymox is. Context
handlers are a 2.6ism.
- I placed a function on the Mox class, which uses another class,
Verification. This seemed more flexible than just saying "with self.mox"
as it allows for other context handlers if necessary.

0001-Add-verification-handler.patch 1.4 KB

Reply all
Reply to author
0 new messages