Add context manager to ease using mox right

Bug #1680481 reported by Martin Häcker
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mox3
New
Undecided
Unassigned

Bug Description

Hi there,

using mox3 right would be much easier if it had a context manager like this:

```
    @contextmanager
    def mox(test_class):
        mox = Mox()
        yield mox
        mox.ReplayAll()

        test_class.addCleanup(mox.UnsetStubs)
```

To be used like this in unit test:

```
def test_something(self):
    with mox(self) as mox:
        mox.StubOutWithMock(FormEditor, 'revert_to_initial_values')
        FormEditor('').revert_to_initial_values('00006')
    # test code that uses the mocked objects
```

Can you please add that to the library? (Naming is of course something you would have to decide on).

Revision history for this message
Martin Häcker (spamfaenger) wrote :

ping @maintainers: any word on this?

Revision history for this message
Martin Häcker (spamfaenger) wrote :

ping @maintainers: anybody here? Is this project still alive?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.