Skip to content

fixture teardown does not seems to execute #9996

Answered by nicoddemus
tr-gis asked this question in General
Discussion options

You must be logged in to vote

Hi @tr-gis,

Could you please tell me what went wrong here ?

Your fixture is returning a function, which you call on the test directly. From the fixture's point of view, there's no teardown phase, because you return an object from it (the object_manager function), and that's it. The fixture can't know that your function yields a value, and that you expect that the function should continue and execute the code after the yield as teardown. The function object has been returned from the fixture, and pytest has no control over it anymore.

The yield mechanism (setup until yield, teardown after) only works if the yield statement is in the body of the fixture function; in your example, your fix…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tr-gis
Comment options

@nicoddemus
Comment options

@tr-gis
Comment options

Answer selected by tr-gis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #9995 on May 26, 2022 12:19.