Aug-31-2019, 06:41 AM
It still sounds like passing in the test by means of a function does exactly what you want. For example:
>>> def is_valid(f): ... try: ... return f() ... except: ... return False ... >>> def always_true(): ... return True ... >>> def always_throws(): ... raise Exception() ... >>> is_valid(always_true) True >>> is_valid(always_throws) False >>>(I didn't have the time to come up with a less contrived example, but hopefully you get the idea).