From feb8240410194c050c881678c97c0d7246ec1ccb Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 13 Sep 2018 15:44:02 -0300 Subject: [PATCH] Use self.Function again during collection --- src/_pytest/python.py | 5 ++++- testing/python/collect.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index dff7a6950..a0a0655fd 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -800,7 +800,10 @@ class Generator(FunctionMixin, PyCollector): "%r generated tests with non-unique name %r" % (self, name) ) seen[name] = True - values.append(Function(name, self, args=args, callobj=call)) + 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) return values diff --git a/testing/python/collect.py b/testing/python/collect.py index c92de12a0..25d8a8e77 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -240,6 +240,9 @@ class TestClass(object): assert result.ret == EXIT_NOTESTSCOLLECTED +@pytest.mark.filterwarnings( + "ignore:usage of Generator.Function is deprecated, please use pytest.Function instead" +) class TestGenerator(object): def test_generative_functions(self, testdir): modcol = testdir.getmodulecol( @@ -1255,6 +1258,9 @@ class TestReportInfo(object): assert lineno == 1 assert msg == "TestClass" + @pytest.mark.filterwarnings( + "ignore:usage of Generator.Function is deprecated, please use pytest.Function instead" + ) def test_generator_reportinfo(self, testdir): modcol = testdir.getmodulecol( """