How to use pytest.yield_fixture and why it be deprecated?
#14435
-
|
Hi everyone, How to use Remember to tag me! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
sorry |
Beta Was this translation helpful? Give feedback.
-
|
@aiwonderland — It still works — but you should migrate. Why it was deprecated: before pytest 3.0, What to use: import pytest
@pytest.fixture
def db_connection():
conn = create_connection() # setup
yield conn # the test runs here
conn.close() # teardownThis is identical to what References:
|
Beta Was this translation helpful? Give feedback.
@aiwonderland —
pytest.yield_fixturewas deprecated in pytest 3.0 (August 2016). The current pytest source still ships it as a thin wrapper that just calls@pytest.fixtureand emits a deprecation warning:It still works — but you should migrate.
Why it was deprecated: before pytest 3.0,
@pytest.fixtureonly supported return-style fixtures; setup/teardown viayieldrequired the separate@pytest.yield_fixturedecorator. In 3.0 the regular@pytest.fixturewas extended to handleyieldas well, making the two decorators do exactly the same thing — so the dedicatedyield_fixturebecame redundant.What to use:
i…