Skip to content

Commit 53bcc63

Browse files
committed
Immediately print exceptions during unit test setup.
1 parent 045d78b commit 53bcc63

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@
3939
import _io
4040
import sys
4141

42-
4342
os = sys.modules.get("posix", sys.modules.get("nt", None))
4443
if os is None:
4544
raise ImportError("posix or nt module is required in builtin modules")
4645

47-
4846
FAIL = '\033[91m'
4947
ENDC = '\033[0m'
5048
BOLD = '\033[1m'
@@ -57,12 +55,13 @@ class SkipTest(BaseException):
5755

5856

5957
class TestCase(object):
58+
6059
def __init__(self):
6160
self.exceptions = []
6261
self.passed = 0
6362
self.failed = 0
6463

65-
def run_safely(self, func):
64+
def run_safely(self, func, print_immediately=False):
6665
if verbose:
6766
print(u"\n\t\u21B3 ", func.__name__, " ", end="")
6867
try:
@@ -71,6 +70,8 @@ def run_safely(self, func):
7170
if isinstance(e, SkipTest):
7271
print("Skipped: %s" % e)
7372
else:
73+
if print_immediately:
74+
print("Exception during setup occurred: %s\n" % e)
7475
code = func.__code__
7576
self.exceptions.append(
7677
("%s:%d (%s)" % (code.co_filename, code.co_firstlineno, func), e)
@@ -95,7 +96,7 @@ def success(self):
9596

9697
def failure(self):
9798
self.failed += 1
98-
fail_msg = FAIL+BOLD+"F"+ENDC if verbose else "F"
99+
fail_msg = FAIL + BOLD + "F" + ENDC if verbose else "F"
99100
print(fail_msg, end="", flush=True)
100101

101102
def assertTrue(self, value, msg=""):
@@ -141,6 +142,7 @@ def assertSequenceEqual(self, expected, actual, msg=None):
141142
assert expected_value == next(actual_iter), msg
142143

143144
class assertRaises():
145+
144146
def __init__(self, exc_type, function=None, *args, **kwargs):
145147
if function is None:
146148
self.exc_type = exc_type
@@ -177,9 +179,9 @@ def run(cls, items=None):
177179
break
178180
items += typ.__dict__.items()
179181
if hasattr(instance, "setUp"):
180-
if not instance.run_safely(instance.setUp):
182+
if not instance.run_safely(instance.setUp, print_immediately=True):
181183
return instance
182-
for k,v in items:
184+
for k, v in items:
183185
if k.startswith("test"):
184186
if patterns:
185187
if not any(p in k for p in patterns):
@@ -198,6 +200,7 @@ class ThisTestCase(cls, TestCase): pass
198200

199201

200202
class TestRunner(object):
203+
201204
def __init__(self, paths):
202205
self.testfiles = TestRunner.find_testfiles(paths)
203206
self.exceptions = []
@@ -255,7 +258,7 @@ def run(self):
255258
print(u"\n\u25B9 ", module.__name__, end="")
256259
# some tests can modify the global scope leading to a RuntimeError: test_scope.test_nesting_plus_free_ref_to_global
257260
module_dict = dict(module.__dict__)
258-
for k,v in module_dict.items():
261+
for k, v in module_dict.items():
259262
if (k.startswith("Test") or k.endswith("Test") or k.endswith("Tests")) and isinstance(v, type):
260263
testcase = TestCase.runClass(v)
261264
else:

0 commit comments

Comments
 (0)