From f3c47238397afa0e2c7ae30d37ace0ff713702f0 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 17 Apr 2020 15:54:14 +0300 Subject: [PATCH 1/2] fixtures: remove compatibility code for outdated "oejskit" plugin This plugin doesn't work with recent pytest releases, and seems abandoned. So remove some compat code for it. It's not quite clear how the exception can be triggered, anyway. Also remove a mention of oejskit from the documentation. --- doc/en/plugins.rst | 3 -- src/_pytest/fixtures.py | 19 +--------- src/_pytest/python.py | 2 +- testing/python/fixtures.py | 6 ++-- testing/python/integration.py | 66 ----------------------------------- 5 files changed, 5 insertions(+), 91 deletions(-) diff --git a/doc/en/plugins.rst b/doc/en/plugins.rst index c3a93141971..5e9134ff939 100644 --- a/doc/en/plugins.rst +++ b/doc/en/plugins.rst @@ -53,9 +53,6 @@ Here is a little annotated list for some popular plugins: * `pytest-flakes `_: check source code with pyflakes. -* `oejskit `_: - a plugin to run javascript unittests in live browsers. - To see a complete list of all plugins with their latest testing status against different pytest and Python versions, please visit `plugincompat `_. diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index f9e0f3b28b5..0200b803c75 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -276,24 +276,7 @@ def reorder_items_atscope(items, argkeys_cache, items_by_argkey, scopenum): def fillfixtures(function): """ fill missing funcargs for a test function. """ - try: - request = function._request - except AttributeError: - # XXX this special code path is only expected to execute - # with the oejskit plugin. It uses classes with funcargs - # and we thus have to work a bit to allow this. - fm = function.session._fixturemanager - fi = fm.getfixtureinfo(function.parent, function.obj, None) - function._fixtureinfo = fi - request = function._request = FixtureRequest(function) - request._fillfixtures() - # prune out funcargs for jstests - newfuncargs = {} - for name in fi.argnames: - newfuncargs[name] = function.funcargs[name] - function.funcargs = newfuncargs - else: - request._fillfixtures() + function._request._fillfixtures() def get_direct_param_fixture_func(request): diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 1f6a095c4e1..2b9bf4f5bb5 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1535,7 +1535,7 @@ def setup(self) -> None: if isinstance(self.parent, Instance): self.parent.newinstance() self.obj = self._getobj() - fixtures.fillfixtures(self) + self._request._fillfixtures() def _prunetraceback(self, excinfo: ExceptionInfo) -> None: if hasattr(self, "_obj") and not self.config.getoption("fulltrace", False): diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 36e55a0e1de..7f10ac19f88 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -109,7 +109,7 @@ def test_detect_recursive_dependency_error(self, testdir): def test_funcarg_basic(self, testdir): testdir.copy_example() item = testdir.getitem(Path("test_funcarg_basic.py")) - fixtures.fillfixtures(item) + item._request._fillfixtures() del item.funcargs["request"] assert len(get_public_names(item.funcargs)) == 2 assert item.funcargs["some"] == "test_func" @@ -663,7 +663,7 @@ def test_func(something): pass assert val2 == 2 val2 = req.getfixturevalue("other") # see about caching assert val2 == 2 - pytest._fillfuncargs(item) + req._fillfixtures() assert item.funcargs["something"] == 1 assert len(get_public_names(item.funcargs)) == 2 assert "request" in item.funcargs @@ -680,7 +680,7 @@ def test_func(something): pass """ ) item.session._setupstate.prepare(item) - pytest._fillfuncargs(item) + item._request._fillfixtures() # successively check finalization calls teardownlist = item.getparent(pytest.Module).obj.teardownlist ss = item.session._setupstate diff --git a/testing/python/integration.py b/testing/python/integration.py index 35e86e6b96c..4925dc98e44 100644 --- a/testing/python/integration.py +++ b/testing/python/integration.py @@ -1,71 +1,5 @@ import pytest from _pytest import python -from _pytest import runner - - -class TestOEJSKITSpecials: - def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage - testdir.makeconftest( - """ - import pytest - def pytest_pycollect_makeitem(collector, name, obj): - if name == "MyClass": - return MyCollector.from_parent(collector, name=name) - class MyCollector(pytest.Collector): - def reportinfo(self): - return self.fspath, 3, "xyz" - """ - ) - modcol = testdir.getmodulecol( - """ - import pytest - @pytest.fixture - def arg1(request): - return 42 - class MyClass(object): - pass - """ - ) - # this hook finds funcarg factories - rep = runner.collect_one_node(collector=modcol) - clscol = rep.result[0] - clscol.obj = lambda arg1: None - clscol.funcargs = {} - pytest._fillfuncargs(clscol) - assert clscol.funcargs["arg1"] == 42 - - def test_autouse_fixture(self, testdir): # rough jstests usage - testdir.makeconftest( - """ - import pytest - def pytest_pycollect_makeitem(collector, name, obj): - if name == "MyClass": - return MyCollector.from_parent(collector, name=name) - class MyCollector(pytest.Collector): - def reportinfo(self): - return self.fspath, 3, "xyz" - """ - ) - modcol = testdir.getmodulecol( - """ - import pytest - @pytest.fixture(autouse=True) - def hello(): - pass - @pytest.fixture - def arg1(request): - return 42 - class MyClass(object): - pass - """ - ) - # this hook finds funcarg factories - rep = runner.collect_one_node(modcol) - clscol = rep.result[0] - clscol.obj = lambda: None - clscol.funcargs = {} - pytest._fillfuncargs(clscol) - assert not clscol.funcargs def test_wrapped_getfslineno(): From 8b579aa0a7ae4df7424d8e19409e108930701e05 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 17 Apr 2020 16:05:43 +0300 Subject: [PATCH 2/2] fixtures: deprecate pytest._fillfuncargs function This function is exposed and kept alive for the oejskit plugin which is abandoned and no longer works with recent plugins, so let's prepare to completely remove it. --- changelog/7097.deprecation.rst | 6 ++++++ doc/en/deprecations.rst | 13 +++++++++++++ src/_pytest/deprecated.py | 5 +++++ src/_pytest/fixtures.py | 2 ++ testing/deprecated_test.py | 9 +++++++++ 5 files changed, 35 insertions(+) create mode 100644 changelog/7097.deprecation.rst diff --git a/changelog/7097.deprecation.rst b/changelog/7097.deprecation.rst new file mode 100644 index 00000000000..ed9779e1f50 --- /dev/null +++ b/changelog/7097.deprecation.rst @@ -0,0 +1,6 @@ +The ``pytest._fillfuncargs`` function is now deprecated. This function was kept +for backward compatibility with an older plugin. + +It's functionality is not meant to be used directly, but if you must replace +it, use `function._request._fillfixtures()` instead, though note this is not +a public API and may break in the future. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 13d59bce2b7..4d8177a543d 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -20,6 +20,19 @@ Below is a complete list of all pytest features which are considered deprecated. :ref:`standard warning filters `. +The ``pytest._fillfuncargs`` function +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 5.5 + +This function was kept for backward compatibility with an older plugin. + +It's functionality is not meant to be used directly, but if you must replace +it, use `function._request._fillfixtures()` instead, though note this is not +a public API and may break in the future. + + + ``--no-print-logs`` command-line option ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 926cfcf19dc..2295bfe1d28 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -25,6 +25,11 @@ "since pytest 2.3 - use the newer attribute instead." ) +FILLFUNCARGS = PytestDeprecationWarning( + "The `_fillfuncargs` function is deprecated, use " + "function._request._fillfixtures() instead if you must." +) + RESULT_LOG = PytestDeprecationWarning( "--result-log is deprecated, please try the new pytest-reportlog plugin.\n" "See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information." diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 0200b803c75..1813020f650 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -28,6 +28,7 @@ from _pytest.compat import NOTSET from _pytest.compat import safe_getattr from _pytest.compat import TYPE_CHECKING +from _pytest.deprecated import FILLFUNCARGS from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS from _pytest.deprecated import FUNCARGNAMES from _pytest.mark import ParameterSet @@ -276,6 +277,7 @@ def reorder_items_atscope(items, argkeys_cache, items_by_argkey, scopenum): def fillfixtures(function): """ fill missing funcargs for a test function. """ + warnings.warn(FILLFUNCARGS, stacklevel=2) function._request._fillfixtures() diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index cf7dee854aa..caa44854f5f 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -1,4 +1,5 @@ import inspect +from unittest import mock import pytest from _pytest import deprecated @@ -146,3 +147,11 @@ def test_foo(): ) assert_no_print_logs(testdir, ()) + + +def test__fillfuncargs_is_deprecated() -> None: + with pytest.warns( + pytest.PytestDeprecationWarning, + match="The `_fillfuncargs` function is deprecated", + ): + pytest._fillfuncargs(mock.Mock())