← Back to team overview

launchpad-dev team mailing list archive

New test helper: FakeTransaction

 

My reviewer encouraged me to share this with you.

I replaced the various {Fake|Mock}Transaction[Manager] classes in our test suite with a single helper, FakeTransaction. It does what you'd expect it to: accept begin(), commit(), and abort() calls and do nothing about them.

Well, optionally it can log commit() and abort(). (Not begin() since in our code it's usually either not present or not meaningful).

    >>> from lp.testing.faketransaction import FakeTransaction
    >>> txn = FakeTransaction()
    >>> txn.begin()
    >>> txn.commit()
    >>> txn.abort()

    >>> txn = FakeTransaction(log_calls=True)
    >>> txn.begin()
    >>> txn.commit()
    COMMIT
    >>> txn.abort()
    ABORT


Jeroen