diff --git a/IPython/utils/tests/test_dir2.py b/IPython/utils/tests/test_dir2.py index 20c601e..d35b110 100644 --- a/IPython/utils/tests/test_dir2.py +++ b/IPython/utils/tests/test_dir2.py @@ -1,5 +1,7 @@ from IPython.utils.dir2 import dir2 +import pytest + class Base(object): x = 1 @@ -35,24 +37,31 @@ def test_SubClass_with_trait_names_attr(): trait_names = 44 res = dir2(SubClass()) - assert('trait_names' in res) + assert "trait_names" in res def test_misbehaving_object_without_trait_names(): # dir2 shouldn't raise even when objects are dumb and raise # something other than AttribteErrors on bad getattr. - class MisbehavingGetattr(object): - def __getattr__(self): + class MisbehavingGetattr: + def __getattr__(self, attr): raise KeyError("I should be caught") def some_method(self): - pass + return True class SillierWithDir(MisbehavingGetattr): def __dir__(self): return ['some_method'] for bad_klass in (MisbehavingGetattr, SillierWithDir): - res = dir2(bad_klass()) - assert('some_method' in res) + obj = bad_klass() + + assert obj.some_method() + + with pytest.raises(KeyError): + obj.other_method() + + res = dir2(obj) + assert "some_method" in res