fix #4400 - rearrange the handling of yield test warnings/errors
This commit is contained in:
parent
9dec146edf
commit
950d30e6e0
|
@ -0,0 +1 @@
|
||||||
|
Rearrange warning handling for the yield test errors so the opt-out in 4.0.x correctly works.
|
|
@ -741,16 +741,20 @@ class FunctionMixin(PyobjMixin):
|
||||||
|
|
||||||
class Generator(FunctionMixin, PyCollector):
|
class Generator(FunctionMixin, PyCollector):
|
||||||
def collect(self):
|
def collect(self):
|
||||||
|
|
||||||
# test generators are seen as collectors but they also
|
# test generators are seen as collectors but they also
|
||||||
# invoke setup/teardown on popular request
|
# invoke setup/teardown on popular request
|
||||||
# (induced by the common "test_*" naming shared with normal tests)
|
# (induced by the common "test_*" naming shared with normal tests)
|
||||||
from _pytest import deprecated
|
from _pytest import deprecated
|
||||||
|
|
||||||
|
self.warn(deprecated.YIELD_TESTS)
|
||||||
|
|
||||||
self.session._setupstate.prepare(self)
|
self.session._setupstate.prepare(self)
|
||||||
# see FunctionMixin.setup and test_setupstate_is_preserved_134
|
# see FunctionMixin.setup and test_setupstate_is_preserved_134
|
||||||
self._preservedparent = self.parent.obj
|
self._preservedparent = self.parent.obj
|
||||||
values = []
|
values = []
|
||||||
seen = {}
|
seen = {}
|
||||||
|
_Function = self._getcustomclass("Function")
|
||||||
for i, x in enumerate(self.obj()):
|
for i, x in enumerate(self.obj()):
|
||||||
name, call, args = self.getcallargs(x)
|
name, call, args = self.getcallargs(x)
|
||||||
if not callable(call):
|
if not callable(call):
|
||||||
|
@ -764,11 +768,7 @@ class Generator(FunctionMixin, PyCollector):
|
||||||
"%r generated tests with non-unique name %r" % (self, name)
|
"%r generated tests with non-unique name %r" % (self, name)
|
||||||
)
|
)
|
||||||
seen[name] = True
|
seen[name] = True
|
||||||
with warnings.catch_warnings():
|
values.append(_Function(name, self, args=args, callobj=call))
|
||||||
# ignore our own deprecation warning
|
|
||||||
function_class = self.Function
|
|
||||||
values.append(function_class(name, self, args=args, callobj=call))
|
|
||||||
self.warn(deprecated.YIELD_TESTS)
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def getcallargs(self, obj):
|
def getcallargs(self, obj):
|
||||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
||||||
|
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
|
||||||
|
|
||||||
|
|
||||||
class SessionTests(object):
|
class SessionTests(object):
|
||||||
|
@ -77,7 +78,8 @@ class SessionTests(object):
|
||||||
"""
|
"""
|
||||||
def test_1():
|
def test_1():
|
||||||
yield None
|
yield None
|
||||||
"""
|
""",
|
||||||
|
SHOW_PYTEST_WARNINGS_ARG,
|
||||||
)
|
)
|
||||||
failures = reprec.getfailedcollections()
|
failures = reprec.getfailedcollections()
|
||||||
out = failures[0].longrepr.reprcrash.message
|
out = failures[0].longrepr.reprcrash.message
|
||||||
|
|
Loading…
Reference in New Issue