On Mon, Nov 19, 2012 at 21:53 +0000, Floris Bruynooghe wrote:

> >     @pytest.fixture(scope="any")
> >     def monkeypatch(...):
> >         # unmodified builtin monkeypatch implementation
> >
> >     @pytest.fixture(scope="module")
> >     def something(monkeypatch):
> >         ...
> >
> > This would not raise a ScopeMismatchError but just work:
> > monkeypatch-finalizers would be called when the last test in a module
> > using the "something" fixture has run.
> >
> > However, if we additionally have a function-scoped fixture::
> >
> >     @pytest.fixture(scope="function")
> >     def other(monkeypatch):
> >         ...
> >
> > The "monkeypatch" instance could obviously not be the same object as
> > the one in ``something(monkeypatch)`` above.  monkeypatch-finalizers
> > would raher be called after a test function using the "other"
> > fixture has finalized.  I am not sure if there is confusion potential
> > about this.
> 
> For monkeypatch this would not be too bad as you can have two
> instances which don't cause harm to each other.  But what happens with
> e.g. tmpdir?  How can you avoid a temporary directory being created at
> the session-level and then later one at the function level?

A tmpdir requested in function-scope and a tmpdir requested with session
scope would be two different directories.  I don't see a problem with this,
do you?

> It's almost as the any-scoped fixture needs to be able to specify how
> things should be handled when it's requested from different scopes.

An any-scoped fixture function can look at request.scope and act accordingly.

An interesting question maybe is: how can a function-scoped resource
_use_ itself but higher scoped :)  (actually not too hard, i guess:
you could just invent a fixture name, have its fixture function use a
higher scope and pass through the resource (e. g. tmpdir).  you can 

best and good night,
holger

_______________________________________________
py-dev mailing list
py-dev@codespeak.net
http://codespeak.net/mailman/listinfo/py-dev

Reply via email to