[py-dev] New plugin: pytest-monkeyplus

holger krekel holger at merlinux.eu
Wed Feb 16 12:39:24 CET 2011

Hi Virgil,

not sure everyone is aware here (or in general) of the "monkeypatch"
funcarg injection, so i first point to an older blog post of mine about it:


it helps a lot if you quickly and safely want to patch global 
module/class attrs, dictionaries, environment variables etc. 
inside a test.

On Wed, Feb 16, 2011 at 10:41 +0100, Virgil Dupras wrote:
> Hi there,
> A few weeks ago I talked about the possibility of adding helpers to the monkeypatch module. Today, I'm publishing a new plugin which I called "monkeyplus" to test the water with these new helpers (patch_osstat, patch_today).
> Repository is at https://bitbucket.org/hsoft/pytest-monkeyplus

I like it from reading your docs,

Would simplify some of my tests.  Maybe others have more suggestions
of what could be useful to have monkeypatch support for? 
we have this currently:

    monkeypatch.setattr(obj, name, value, raising=True)
    monkeypatch.delattr(obj, name, raising=True)
    monkeypatch.setitem(mapping, name, value)
    monkeypatch.delitem(obj, name, raising=True)
    monkeypatch.setenv(name, value, prepend=False)
    monkeypatch.delenv(name, value, raising=True)

and with Virgils monkeyplus:

    monkeyplus.patch_osstat('foo/bar', st_mtime=42)
    monkeyplus.patch_today(year, month, day)
from my side, for consistency the names should eventually be 

    monkeypatch.osstat(path, **attrs)
    monkeypatch.today(year, month, day)

If more people like such additions i'd be happy to incorporate
a patch for the next release.


> Virgil Dupras
> _______________________________________________
> py-dev mailing list
> py-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/py-dev


More information about the Pytest-dev mailing list