On Tue, Sep 17, 2013 at 14:46 +0200, Antonio Cuni wrote:
> On 17/09/13 12:13, holger krekel wrote:
> >Not sure it would even be that useful TBH and would indeed be trickier
> >to implement, i guess.  Maybe it's better to rather think about
> >higher level helpers than argue much about the setattr() convenience.
> 
> I think that designing a good API is not only about convenience, but
> it has a high impact on how easy it is to learn to use the tool.
> 
> I just though of another variation on the theme:
> 
> monkeypatch(os.path).abspath = foobar # OR
> monkey(os.path).abspath = foobar

> I think this is the easiest to remember, to understand and it's also
> probably very easy to implement.

not sure it's easy to remember given that several different somewhat
popular approaches all don't look like this.  But it's a cute trick 
that indeed wouldn't be hard to implement :)

> >Apart from the proposed setattr shortcut, i am also thinking of
> >direct mock (the lib from Michael Foord) support:
> >
> >     mock = monkeypatch.setmock("os.path.abspath")
> 
> not sure it's a good idea. I don't think it is much simpler than this:
> 
>     mock = monekypatch.setattr("os.path.abspath", Mock())
> 
> apart that in the latter case you must import Mock explicitly, which
> is a good thing IMHO.

Not sure i agree with "importing is a good thing" :) For fixtures people
have come to appreciate, i think, the de-coupling of using values and
providing them.  Mocking is tightly connected with testing so having
a builtin support fixture is reasonable IIRC.

Also, with monkeypatch.setattr(..., Mock()) you cannot easily do "autospec"
whereas with monkeypatch.setmock(...) you could (And disable with
autospec=False).  Or maybe a new "mock" and "mock.patch(...)" would
be even easier for people knowing mock's API -- except that "mock"
would be a fixture provided by pytest or a plugin, and mock.patch
would be an imperative call.

best,
holger
_______________________________________________
Pytest-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to