From 47bd1688ed0da460fc6b1885e82bb9aa5bd1c3e0 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 25 Feb 2019 19:37:27 -0300 Subject: [PATCH 1/3] Remove dead-code related to yield tests Just noticed some code that no longer is needed when we removed yield-tests --- changelog/4829.trivial.rst | 1 + src/_pytest/debugging.py | 17 ++++++----------- src/_pytest/python.py | 31 +++++++++---------------------- 3 files changed, 16 insertions(+), 33 deletions(-) create mode 100644 changelog/4829.trivial.rst diff --git a/changelog/4829.trivial.rst b/changelog/4829.trivial.rst new file mode 100644 index 000000000..a1935b462 --- /dev/null +++ b/changelog/4829.trivial.rst @@ -0,0 +1 @@ +Some left-over internal code related to ``yield`` tests has been removed. diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index 271a590a1..6dbc0499a 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -209,17 +209,12 @@ def _test_pytest_function(pyfuncitem): _pdb = pytestPDB._init_pdb() testfunction = pyfuncitem.obj pyfuncitem.obj = _pdb.runcall - if pyfuncitem._isyieldedfunction(): - arg_list = list(pyfuncitem._args) - arg_list.insert(0, testfunction) - pyfuncitem._args = tuple(arg_list) - else: - if "func" in pyfuncitem._fixtureinfo.argnames: - raise ValueError("--trace can't be used with a fixture named func!") - pyfuncitem.funcargs["func"] = testfunction - new_list = list(pyfuncitem._fixtureinfo.argnames) - new_list.append("func") - pyfuncitem._fixtureinfo.argnames = tuple(new_list) + if "func" in pyfuncitem._fixtureinfo.argnames: + raise ValueError("--trace can't be used with a fixture named func!") + pyfuncitem.funcargs["func"] = testfunction + new_list = list(pyfuncitem._fixtureinfo.argnames) + new_list.append("func") + pyfuncitem._fixtureinfo.argnames = tuple(new_list) def _enter_pdb(node, excinfo, rep): diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 215015d27..537c42d0d 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -156,14 +156,9 @@ def pytest_configure(config): @hookimpl(trylast=True) def pytest_pyfunc_call(pyfuncitem): testfunction = pyfuncitem.obj - if pyfuncitem._isyieldedfunction(): - testfunction(*pyfuncitem._args) - else: - funcargs = pyfuncitem.funcargs - testargs = {} - for arg in pyfuncitem._fixtureinfo.argnames: - testargs[arg] = funcargs[arg] - testfunction(**testargs) + funcargs = pyfuncitem.funcargs + testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames} + testfunction(**testargs) return True @@ -1405,7 +1400,7 @@ class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr): if fixtureinfo is None: fixtureinfo = self.session._fixturemanager.getfixtureinfo( - self, self.obj, self.cls, funcargs=not self._isyieldedfunction() + self, self.obj, self.cls, funcargs=True ) self._fixtureinfo = fixtureinfo self.fixturenames = fixtureinfo.names_closure @@ -1419,16 +1414,11 @@ class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr): def _initrequest(self): self.funcargs = {} - if self._isyieldedfunction(): - assert not hasattr( - self, "callspec" - ), "yielded functions (deprecated) cannot have funcargs" - else: - if hasattr(self, "callspec"): - callspec = self.callspec - assert not callspec.funcargs - if hasattr(callspec, "param"): - self.param = callspec.param + if hasattr(self, "callspec"): + callspec = self.callspec + assert not callspec.funcargs + if hasattr(callspec, "param"): + self.param = callspec.param self._request = fixtures.FixtureRequest(self) @property @@ -1448,9 +1438,6 @@ class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr): "(compatonly) for code expecting pytest-2.2 style request objects" return self - def _isyieldedfunction(self): - return getattr(self, "_args", None) is not None - def runtest(self): """ execute the underlying test function. """ self.ihook.pytest_pyfunc_call(pyfuncitem=self) From 148e6a30c82fd707e00fdd3d169fa6f4b0cf42dd Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 6 Mar 2019 19:01:27 -0300 Subject: [PATCH 2/3] Improve coverage --- src/_pytest/debugging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index 6dbc0499a..6d51ec59c 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -209,7 +209,7 @@ def _test_pytest_function(pyfuncitem): _pdb = pytestPDB._init_pdb() testfunction = pyfuncitem.obj pyfuncitem.obj = _pdb.runcall - if "func" in pyfuncitem._fixtureinfo.argnames: + if "func" in pyfuncitem._fixtureinfo.argnames: # noqa raise ValueError("--trace can't be used with a fixture named func!") pyfuncitem.funcargs["func"] = testfunction new_list = list(pyfuncitem._fixtureinfo.argnames) From b7ae7a654b672ef3d6f496385c7dd6884e077ea7 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 6 Mar 2019 19:08:34 -0300 Subject: [PATCH 3/3] Remove callspec related block of code It seems this is no longer required now that we don't support yield tests anymore. The param attribute was added here: https://github.com/pytest-dev/pytest/blob/91b6f2bda8668e0f74190ed223a9eec01d09a0a7/_pytest/python.py#L888-L891 --- src/_pytest/python.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 537c42d0d..e41acfecc 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1414,11 +1414,6 @@ class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr): def _initrequest(self): self.funcargs = {} - if hasattr(self, "callspec"): - callspec = self.callspec - assert not callspec.funcargs - if hasattr(callspec, "param"): - self.param = callspec.param self._request = fixtures.FixtureRequest(self) @property