Add context manager to ease using mox right

Bug #1680481 reported by Martin Häcker on 2017-04-06
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mox3
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).

Martin Häcker (spamfaenger) wrote :

ping @maintainers: any word on this?

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  Edit
Everyone can see this information.

Other bug subscribers