From cb21a8db1d0dbbf1284eb0e644a8cd7b8fc837be Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 7 Nov 2019 11:43:59 +0100 Subject: [PATCH] test_source: do not instantiate Source objects during collection --- testing/code/test_source.py | 43 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/testing/code/test_source.py b/testing/code/test_source.py index 15e0bf24a..5e7e1abf5 100644 --- a/testing/code/test_source.py +++ b/testing/code/test_source.py @@ -127,14 +127,15 @@ def test_isparseable(): class TestAccesses: - source = Source( - """\ - def f(x): - pass - def g(x): - pass - """ - ) + def setup_class(self): + self.source = Source( + """\ + def f(x): + pass + def g(x): + pass + """ + ) def test_getrange(self): x = self.source[0:2] @@ -155,14 +156,15 @@ class TestAccesses: class TestSourceParsingAndCompiling: - source = Source( - """\ - def f(x): - assert (x == - 3 + - 4) - """ - ).strip() + def setup_class(self): + self.source = Source( + """\ + def f(x): + assert (x == + 3 + + 4) + """ + ).strip() def test_compile(self): co = _pytest._code.compile("x=3") @@ -619,7 +621,8 @@ x = 3 class TestTry: - source = """\ + def setup_class(self): + self.source = """\ try: raise ValueError except Something: @@ -646,7 +649,8 @@ else: class TestTryFinally: - source = """\ + def setup_class(self): + self.source = """\ try: raise ValueError finally: @@ -663,7 +667,8 @@ finally: class TestIf: - source = """\ + def setup_class(self): + self.source = """\ if 1: y = 3 elif False: