Skip to content

Commit 4af1098

Browse files
committed
Fix setUp vs setupClass in graalpytest
1 parent 1640549 commit 4af1098

File tree

8 files changed

+35
-28
lines changed

8 files changed

+35
-28
lines changed

graalpython/com.oracle.graal.python.test/src/graalpytest.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,16 @@ def run_test(self, func):
380380
pass
381381
else:
382382
def do_run():
383+
if hasattr(self, "setUp"):
384+
if not self.run_safely(self.setUp, print_immediately=True):
385+
self.failure(0)
386+
return
383387
start = time.monotonic()
384388
r = self.run_safely(func)
385389
end = time.monotonic() - start
390+
if hasattr(self, "tearDown"):
391+
if not self.run_safely(self.tearDown):
392+
self.failure(end)
386393
with print_lock:
387394
if r is _skipped_marker:
388395
self.skipped()
@@ -528,17 +535,17 @@ def run(cls, items=None):
528535
if typ is TestCase:
529536
break
530537
items += typ.__dict__.items()
531-
if hasattr(instance, "setUp"):
532-
if not instance.run_safely(instance.setUp, print_immediately=True):
538+
if hasattr(instance, "setUpClass"):
539+
if not instance.run_safely(instance.setUpClass, print_immediately=True):
533540
return instance
534541
for k, v in items:
535542
if k.startswith("test"):
536543
if patterns:
537544
if not any(p in k for p in patterns):
538545
continue
539546
instance.run_test(getattr(instance, k, v))
540-
if hasattr(instance, "tearDown"):
541-
instance.run_safely(instance.tearDown)
547+
if hasattr(instance, "tearDownClass"):
548+
instance.run_safely(instance.tearDownClass)
542549
return instance
543550

544551
@staticmethod

graalpython/com.oracle.graal.python.test/src/tests/cpyext/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def unhandled_error_compare_with_message(x, y):
6262

6363
class CPyExtTestCase():
6464

65-
def setUp(self):
65+
def setUpClass(self):
6666
for typ in type(self).mro():
6767
for k, v in typ.__dict__.items():
6868
if k.startswith("test_"):

graalpython/com.oracle.graal.python.test/src/tests/test__class__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def find_code_object(t):
4848

4949
class BasicTests(unittest.TestCase):
5050

51-
def tearDown(self):
51+
def tearDownClass(self):
5252
nonlocal __class__
5353
__class__ = BasicTests
5454

graalpython/com.oracle.graal.python.test/src/tests/test_mmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
class MmapTests(unittest.TestCase):
2121

22-
def setUp(self):
22+
def setUpClass(self):
2323
if os.path.exists(TESTFN):
2424
os.unlink(TESTFN)
2525

26-
def tearDown(self):
26+
def tearDownClass(self):
2727
try:
2828
os.unlink(TESTFN)
2929
except OSError:

graalpython/com.oracle.graal.python.test/src/tests/test_subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_os_pipe():
1313

1414

1515
class TestSubprocess(unittest.TestCase):
16-
def setUp(self):
16+
def setUpClass(self):
1717
global subprocess, io, sys
1818
import subprocess, io, sys
1919

graalpython/com.oracle.graal.python.test/src/tests/test_thread.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def verbose_print(arg):
7474

7575
class BasicThreadTest(unittest.TestCase):
7676

77-
def setUp(self):
77+
def setUpClass(self):
7878
self.done_mutex = thread.allocate_lock()
7979
self.done_mutex.acquire()
8080
self.running_mutex = thread.allocate_lock()
@@ -85,7 +85,7 @@ def setUp(self):
8585

8686
self._threads = support.threading_setup()
8787

88-
def tearDown(self):
88+
def tearDownClass(self):
8989
support.threading_cleanup(*self._threads)
9090

9191

@@ -296,10 +296,10 @@ def do_finish(self):
296296
class BaseTestCase(unittest.TestCase):
297297
failureException = AssertionError
298298

299-
def setUp(self):
299+
def setUpClass(self):
300300
self._threads = support.threading_setup()
301301

302-
def tearDown(self):
302+
def tearDownClass(self):
303303
support.threading_cleanup(*self._threads)
304304
# TODO: revert patch when os.waitpid(-1, ...) is implemented
305305
# support.reap_children()

graalpython/com.oracle.graal.python.test/src/tests/test_venv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646

4747

4848
class VenvTest():
49-
def setUp(self):
49+
def setUpClass(self):
5050
self.env_dir = os.path.realpath(tempfile.mkdtemp())
5151
self.env_dir2 = os.path.realpath(tempfile.mkdtemp())
5252

53-
def tearDown(self):
53+
def tearDownClass(self):
5454
shutil.rmtree(self.env_dir)
5555
shutil.rmtree(self.env_dir2)
5656

graalpython/com.oracle.graal.python.test/src/tests/test_zipimport.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ def get_file():
3535

3636
class ZipImportBaseTestCase(unittest.TestCase):
3737

38-
def setUp(self):
38+
def setUpClass(self):
3939
zipimport._zip_directory_cache.clear()
4040
self.path = sys.path[:]
4141
self.meta_path = sys.meta_path[:]
4242
self.path_hooks = sys.path_hooks[:]
4343
sys.path_importer_cache.clear()
4444
self.modules_before = support.modules_setup()
4545

46-
def tearDown(self):
46+
def tearDownClass(self):
4747
sys.path[:] = self.path
4848
sys.meta_path[:] = self.meta_path
4949
sys.path_hooks[:] = self.path_hooks
@@ -52,8 +52,8 @@ def tearDown(self):
5252

5353
class BasicZipImportTests(ZipImportBaseTestCase):
5454

55-
def setUp(self):
56-
ZipImportBaseTestCase.setUp(self)
55+
def setUpClass(self):
56+
ZipImportBaseTestCase.setUpClass(self)
5757
self.z = zipimport.zipimporter(ZIP_PATH)
5858

5959
def test_zipimporter_attribute(self):
@@ -147,11 +147,11 @@ def test_zipimporter_load_module(self):
147147

148148
class ZipImportWithPrefixTests(ZipImportBaseTestCase):
149149

150-
def setUp(self):
151-
ZipImportBaseTestCase.setUp(self)
150+
def setUpClass(self):
151+
ZipImportBaseTestCase.setUpClass(self)
152152
self.z = zipimport.zipimporter(ZIP_PATH + "/cesta")
153153

154-
def tearDown(self):
154+
def tearDownClass(self):
155155
zipimport._zip_directory_cache.clear()
156156

157157
def test_zipimporter_with_prefix_attribute(self):
@@ -172,8 +172,8 @@ def test_zipimporter_with_prefix_find_module(self):
172172

173173
class ImportTests(ZipImportBaseTestCase):
174174

175-
def setUp(self):
176-
ZipImportBaseTestCase.setUp(self)
175+
def setUpClass(self):
176+
ZipImportBaseTestCase.setUpClass(self)
177177
sys.path.insert(0, ZIP_PATH)
178178

179179
def test_module_import(self):
@@ -184,8 +184,8 @@ def test_module_import(self):
184184

185185
class BasicEggImportTests(ZipImportBaseTestCase):
186186

187-
def setUp(self):
188-
ZipImportBaseTestCase.setUp(self)
187+
def setUpClass(self):
188+
ZipImportBaseTestCase.setUpClass(self)
189189
self.z = zipimport.zipimporter(EGG_PATH)
190190

191191
def test_zipimporter_egg(self):
@@ -208,8 +208,8 @@ def test_egg_get_readme(self):
208208
class GR15813ImportTests(ZipImportBaseTestCase):
209209

210210
# don't edit the zip file !!!
211-
def setUp(self):
212-
ZipImportBaseTestCase.setUp(self)
211+
def setUpClass(self):
212+
ZipImportBaseTestCase.setUpClass(self)
213213
self.z = zipimport.zipimporter(GR15813_PATH)
214214

215215
def test_zipimporter_gr_18813(self):

0 commit comments

Comments
 (0)