Skip to content

Commit ff0a153

Browse files
authored
Merge pull request #55 from spacetelescope/cds_more_py3_fixes
fix minipyt runner on py3 to find class methods
2 parents 4a1f3d9 + e42e80d commit ff0a153

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

pandokia/helpers/runner_minipyt.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,26 @@ def get_exception_str():
234234

235235
def locate_test_methods(ob, test_order):
236236
l = []
237-
238-
# look through the class for methods that are interesting to us.
239-
240-
for f_name, f_ob in inspect.getmembers(ob, inspect.ismethod):
237+
f_names_found = []
238+
239+
# Look through the class for methods that are interesting to us.
240+
methodish_things = inspect.getmembers(ob, inspect.ismethod)
241+
242+
# For some reason in py3 inspect isn't finding our class tests methods
243+
# in the HST ETC versions test class. Adding the isfunction filter grabs
244+
# them correctly and will not hurt to add, because: 1) duplicates are weeded
245+
# out, and 2) each function found will be tested for the presence of
246+
# the __test__ attr. below.
247+
if sys.version_info[0] > 2:
248+
methodish_things = methodish_things + inspect.getmembers(ob, inspect.isfunction)
249+
250+
for f_name, f_ob in methodish_things:
251+
252+
# prevent duplicates
253+
if f_name in f_names_found:
254+
continue
255+
else:
256+
f_names_found.append(f_name)
241257

242258
# if the method has __test__, that value is a flag
243259
# about whether it is a test or not. Note there are
@@ -369,6 +385,7 @@ def run_test_class_single(rpt, mod, name, ob, test_order):
369385
class_ob = ob()
370386
except:
371387
exception_str = get_exception_str()
388+
debug_fd.write('bailing out early trying to instantiate class %s, named %s, for: %s\n' % (ob, name, exception_str))
372389
traceback.print_exc()
373390
# really nothing more we can do...
374391
gen_report(rpt, name, 'E', class_start_time, time.time(), {}, {
@@ -669,7 +686,6 @@ def process_file(filename, test_name=None, test_args=None):
669686
module, inspect.isfunction) + inspect.getmembers(module, inspect.isclass):
670687
if debug:
671688
debug_fd.write("process_file: inspect name %s\n" % name)
672-
673689
try:
674690
# if it has minipyt_test, that value is a flag
675691
# about whether it is a test or not.

0 commit comments

Comments
 (0)