Skip to content

Commit

Permalink
fix pytest-dev#4400 - rearrange the handling of yield test warnings/e…
Browse files Browse the repository at this point in the history
…rrors
  • Loading branch information
RonnyPfannschmidt committed Nov 16, 2018
1 parent 9dec146 commit e185da2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/4400.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rearragne warning handling for the yield test errors so the opt-out in 4.0.x correctly works.
10 changes: 5 additions & 5 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,16 +741,20 @@ def repr_failure(self, excinfo, outerr=None):

class Generator(FunctionMixin, PyCollector):
def collect(self):

# test generators are seen as collectors but they also
# invoke setup/teardown on popular request
# (induced by the common "test_*" naming shared with normal tests)
from _pytest import deprecated

self.warn(deprecated.YIELD_TESTS)

self.session._setupstate.prepare(self)
# see FunctionMixin.setup and test_setupstate_is_preserved_134
self._preservedparent = self.parent.obj
values = []
seen = {}
_Function = self._getcustomclass("Function")
for i, x in enumerate(self.obj()):
name, call, args = self.getcallargs(x)
if not callable(call):
Expand All @@ -764,11 +768,7 @@ def collect(self):
"%r generated tests with non-unique name %r" % (self, name)
)
seen[name] = True
with warnings.catch_warnings():
# ignore our own deprecation warning
function_class = self.Function
values.append(function_class(name, self, args=args, callobj=call))
self.warn(deprecated.YIELD_TESTS)
values.append(_Function(name, self, args=args, callobj=call))
return values

def getcallargs(self, obj):
Expand Down

0 comments on commit e185da2

Please sign in to comment.