[py-dev] py.test and asserts in method_teardown
holger krekel
holger at merlinux.de
Wed Aug 8 22:36:44 CEST 2007
Hi Johan,
On Wed, Aug 08, 2007 at 12:57 -0700, Johan Björk wrote:
> Thanks for the response.
> Just to make sure, teardown_method IS supposed to be called at every
> teardown right? I'm setting up some state in databases that it's
> pretty important that I clean up (even if there are no following test)
for each setup_X the according teardown_X is called
with X being "module", "class" or "method". However, in the
curent code base, the invocation of teardowns is indeed done
lazily (as Maciej points out), i.e. for
def teardown_method(self): ...
def test_1(self): ...
def test_2(self): ...
teardown_method(self, test_1) will be called
when the test_2 is actually setup. This serves
to avoid un-neccessary teardown/setup cycles.
However for methods, including generative test methods
(those having a "yield" in them), we could probably
see to teardown less lazily as its clear that teardown
needs to be called on the next test, anyway.
In any case, your reported situation highlights a
reporting bug as it relates the failure to
the wrong test method. I guess it makes sense to
aim at a more specialized reporting of setup/teardown
problems.
best & thanks for pointing the problem out,
holger
> /Johan
>
> On 8/8/07, Maciek Fijalkowski <fijal at genesilico.pl> wrote:
> > Johan Björk wrote:
> > > Hi,
> > >
> > > First post on the list, please excuse me if I don't follow normal
> > > guidelines for posting here...
> > >
> > >
> > > I'm having an assert in my method_teardown, which gives rather
> > > confusing results.
> > >
> > > See attached short example (ugly)
> > > Running py.test on this testclass, you will get an output similar to:
> > >
> > > entrypoint: TestMyClass().testApa3 _________________________________________
> > >
> > > def teardown_method(self,method):
> > > if(salmon):
> > > E assert 0
> > >
> > >> assert 0
> > >>
> > >
> > > [/Users/phb/Documents/Development/radar/pytest/test_class.py:9]
> > >
> > > I would have expected to get "testApa2" as the entrypoint.
> > >
> > > Ideas?
> > >
> > > Thanks
> > > /Johan
> > >
> > >
> > Yes, this is known issue, although thanks for spotting.
> >
> > The reason is that teardown_method is called only when trying to access
> > next test. I hope to have it fixed this week. (I can explain in more
> > detail if you're interested)
> >
> > Cheers,
> > fijal
> >
> >
> > PS Posting this way is perfectly fine.
> >
> >
> >
> > :.
> >
> >
> _______________________________________________
> py-dev mailing list
> py-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/py-dev
>
--
merlinux GmbH Steinbergstr. 42 31139 Hildesheim
http://merlinux.de tel +49 5121 20800 75 (fax 77)
More information about the Pytest-dev
mailing list