See if attributes exist before testing them

Avoid throwing exceptions.NameError: global name 'pty' is not defined