1# test __getattr__ on module 2 3# ensure that does_not_exist doesn't exist to start with 4this = __import__(__name__) 5try: 6 this.does_not_exist 7 assert False 8except AttributeError: 9 pass 10 11# define __getattr__ 12def __getattr__(attr): 13 if attr == "does_not_exist": 14 return False 15 raise AttributeError 16 17 18# do feature test (will also test functionality if the feature exists) 19if not hasattr(this, "does_not_exist"): 20 print("SKIP") 21 raise SystemExit 22 23# check that __getattr__ works as expected 24print(this.does_not_exist) 25