diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 593b81fa6..7213e772e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -185,7 +185,8 @@ Before, you only got exceptions later from ``argparse`` library, giving no clue about the actual reason for double-added options. -* +* ``yield``-based tests are considered deprecated and will be removed in pytest-4.0. + Thanks `@nicoddemus`_ for the PR. * diff --git a/_pytest/python.py b/_pytest/python.py index 79502ce1a..4a4cd5dc4 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -589,6 +589,8 @@ 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)) + msg = 'yield tests are deprecated, and scheduled to be removed in pytest 4.0' + self.config.warn('C1', msg, fslocation=self.fspath) return l def getcallargs(self, obj): @@ -611,8 +613,6 @@ def hasinit(obj): return True - - class CallSpec2(object): def __init__(self, metafunc): self.metafunc = metafunc diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index c5401cda6..ff56da3b1 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -762,3 +762,18 @@ class TestDurationWithFixture: * setup *test_1* * call *test_1* """) + + +def test_yield_tests_deprecation(testdir): + testdir.makepyfile(""" + def func1(arg, arg2): + assert arg == arg2 + def test_gen(): + yield "m1", func1, 15, 3*5 + yield "m2", func1, 42, 6*7 + """) + result = testdir.runpytest('-ra') + result.stdout.fnmatch_lines([ + '*yield tests are deprecated, and scheduled to be removed in pytest 4.0*', + '*2 passed*', + ]) diff --git a/testing/code/test_source.py b/testing/code/test_source.py index e78f4b241..13bfccd54 100644 --- a/testing/code/test_source.py +++ b/testing/code/test_source.py @@ -285,13 +285,14 @@ class TestSourceParsingAndCompiling: #print "block", str(block) assert str(stmt).strip().startswith('assert') - def test_compilefuncs_and_path_sanity(self): + @pytest.mark.parametrize('name', ['', None, 'my']) + def test_compilefuncs_and_path_sanity(self, name): def check(comp, name): co = comp(self.source, name) if not name: - expected = "codegen %s:%d>" %(mypath, mylineno+2+1) + expected = "codegen %s:%d>" %(mypath, mylineno+2+2) else: - expected = "codegen %r %s:%d>" % (name, mypath, mylineno+2+1) + expected = "codegen %r %s:%d>" % (name, mypath, mylineno+2+2) fn = co.co_filename assert fn.endswith(expected) @@ -300,8 +301,7 @@ class TestSourceParsingAndCompiling: mypath = mycode.path for comp in _pytest._code.compile, _pytest._code.Source.compile: - for name in '', None, 'my': - yield check, comp, name + check(comp, name) def test_offsetless_synerr(self): pytest.raises(SyntaxError, _pytest._code.compile, "lambda a,a: 0", mode='eval')