Make YIELD_TEST warning less spammy

Emit it only once per each generator, rather than for each generated
function. Also add information about which test caused it to be emitted.
This commit is contained in:
Pauli Virtanen 2017-07-10 21:07:55 +02:00
parent 7cd03d7611
commit 8a7d98fed9
3 changed files with 6 additions and 1 deletions

View File

@ -615,7 +615,7 @@ class Generator(FunctionMixin, PyCollector):
raise ValueError("%r generated tests with non-unique name %r" %(self, name))
seen[name] = True
l.append(self.Function(name, self, args=args, callobj=call))
self.config.warn('C1', deprecated.YIELD_TESTS, fslocation=self.fspath)
self.warn('C1', deprecated.YIELD_TESTS)
return l
def getcallargs(self, obj):

1
changelog/2562.trivial Normal file
View File

@ -0,0 +1 @@
Emit yield test warning only once per generator

View File

@ -9,12 +9,16 @@ def test_yield_tests_deprecation(testdir):
def test_gen():
yield "m1", func1, 15, 3*5
yield "m2", func1, 42, 6*7
def test_gen2():
for k in range(10):
yield func1, 1, 1
""")
result = testdir.runpytest('-ra')
result.stdout.fnmatch_lines([
'*yield tests are deprecated, and scheduled to be removed in pytest 4.0*',
'*2 passed*',
])
assert result.stdout.str().count('yield tests are deprecated') == 2
def test_funcarg_prefix_deprecation(testdir):