From f00bec2a12a585eee245284c8eac86edc27e661f Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 25 Jun 2020 14:05:46 +0300 Subject: [PATCH] Replace yield_fixture -> fixture in internal code `yield_fixture` is a deprecated alias to `fixture`. --- src/_pytest/fixtures.py | 4 +--- src/_pytest/recwarn.py | 4 ++-- testing/example_scripts/issue_519.py | 4 ++-- testing/python/fixtures.py | 5 ++--- testing/test_doctest.py | 2 +- testing/test_pathlib.py | 2 +- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 4b2c6a774..9423df7e4 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -924,9 +924,7 @@ def _teardown_yield_fixture(fixturefunc, it) -> None: except StopIteration: pass else: - fail_fixturefunc( - fixturefunc, "yield_fixture function has more than one 'yield'" - ) + fail_fixturefunc(fixturefunc, "fixture function has more than one 'yield'") def _eval_scope_callable( diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index 57034be2a..eed79c3fd 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -13,14 +13,14 @@ from typing import Union from _pytest.compat import overload from _pytest.compat import TYPE_CHECKING -from _pytest.fixtures import yield_fixture +from _pytest.fixtures import fixture from _pytest.outcomes import fail if TYPE_CHECKING: from typing import Type -@yield_fixture +@fixture def recwarn(): """Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions. diff --git a/testing/example_scripts/issue_519.py b/testing/example_scripts/issue_519.py index 52d5d3f55..021dada49 100644 --- a/testing/example_scripts/issue_519.py +++ b/testing/example_scripts/issue_519.py @@ -33,13 +33,13 @@ def checked_order(): ] -@pytest.yield_fixture(scope="module") +@pytest.fixture(scope="module") def fix1(request, arg1, checked_order): checked_order.append((request.node.name, "fix1", arg1)) yield "fix1-" + arg1 -@pytest.yield_fixture(scope="function") +@pytest.fixture(scope="function") def fix2(request, fix1, arg2, checked_order): checked_order.append((request.node.name, "fix2", arg2)) yield "fix2-" + arg2 + fix1 diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index e14385144..3efbbe107 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -1315,7 +1315,7 @@ class TestFixtureUsages: DB_INITIALIZED = None - @pytest.yield_fixture(scope="session", autouse=True) + @pytest.fixture(scope="session", autouse=True) def db(): global DB_INITIALIZED DB_INITIALIZED = True @@ -2960,8 +2960,7 @@ class TestFixtureMarker: """ import pytest - @pytest.yield_fixture(params=[object(), object()], - ids=['alpha', 'beta']) + @pytest.fixture(params=[object(), object()], ids=['alpha', 'beta']) def fix(request): yield request.param diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 2b98b5267..9ef9417cd 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -1176,7 +1176,7 @@ class TestDoctestAutoUseFixtures: import pytest import sys - @pytest.yield_fixture(autouse=True, scope='session') + @pytest.fixture(autouse=True, scope='session') def myfixture(): assert not hasattr(sys, 'pytest_session_data') sys.pytest_session_data = 1 diff --git a/testing/test_pathlib.py b/testing/test_pathlib.py index 126e1718e..d9d3894f9 100644 --- a/testing/test_pathlib.py +++ b/testing/test_pathlib.py @@ -91,7 +91,7 @@ class TestImportPath: Having our own pyimport-like function is inline with removing py.path dependency in the future. """ - @pytest.yield_fixture(scope="session") + @pytest.fixture(scope="session") def path1(self, tmpdir_factory): path = tmpdir_factory.mktemp("path") self.setuptestfs(path)