[pytest-dev] Using a context manager in a funcarg/fixture

holger krekel holger at merlinux.eu
Tue Apr 23 09:39:23 CEST 2013


Hi Brianna, all,

On Tue, Apr 23, 2013 at 07:20 +0000, holger krekel wrote:
> Hi Brianna,
> 
> On Mon, Apr 22, 2013 at 15:48 +1000, Brianna Laugher wrote:
> > Hi folks,
> > 
> > I posted this a couple of weeks ago and would appreciate if anyone can
> > offer a useful answer.
> > 
> > http://stackoverflow.com/questions/15801662/py-test-how-to-use-a-context-manager-in-a-funcarg-fixture
> > 
> > I feel like some kind of fixture definition that involves a yield statement
> > could be usefulfor this?
> 
> I guess some playing around with adding direct support for context
> managers as fixtures could be interesting.  Not bound to do that anytime soon
> myself, though.

for clarification why i think this needs more discussion and playing
around: what exactly should a fixturemanagers __exit__() see
as exception value?  If we have multiple "contextmanager" fixtures like this:

    def test_fixtures(fix1, fix2, fix3, ...):

and fix2's setup fails, should fix1's __exit__ see that exception?
Or should only exceptions from the actual test body be seen and then
be seen by each fixN's __exit__ repeatedly?

What about fixtures that have caching scopes higher than "function"?
Should they ever receive exceptions in their __exit__?

best,
holger

> holger
> 
> > cheers
> > Brianna
> > 
> > 
> > -- 
> > They've just been waiting in a mountain for the right moment:
> > http://modernthings.org/
> 
> > _______________________________________________
> > Pytest-dev mailing list
> > Pytest-dev at python.org
> > http://mail.python.org/mailman/listinfo/pytest-dev
> 
> _______________________________________________
> Pytest-dev mailing list
> Pytest-dev at python.org
> http://mail.python.org/mailman/listinfo/pytest-dev
> 


More information about the Pytest-dev mailing list