[py-dev] py.test and asserts in method_teardown
Maciek Fijalkowski
fijal at genesilico.pl
Wed Aug 8 22:19:23 CEST 2007
Johan Björk wrote:
> Hi,
> 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)
>
> /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.
>>
>>
>>
>> :.
>>
>>
Yes, teardown will be called. The only place where you don't call it is
if you have no test at all.
like:
class X:
def setup_method(cls):
stuff
def teardown_method(cls):
stuff
otherwise it'll be called
:.
More information about the Pytest-dev
mailing list