anshulxyz / exch

a command-line tool to see currency exchange rates
MIT License
20 stars 2 forks source link

Exception handling request #14

Closed anshulxyz closed 7 years ago

anshulxyz commented 7 years ago

Though I didn't achieve the goal I had in mind, I did learn something. So, I think I have found a workaround for my issue, I was getting this from pytest:

>       assert result.exception == KeyError()
E       assert KeyError() == KeyError()
E        +  where KeyError() = <Result KeyError()>.exception
E        +  and   KeyError() = KeyError()

tests/test_advanced.py:21: AssertionError

but now I changed the line a little bit:

-    assert result.exception == KeyError()
+    assert type(result.exception) == type(KeyError())

and to give you some clarity:

>>> type(KeyError())
<class 'KeyError'>
>>> type(KeyError)
<class 'type'>
>>> type(KeyError()) == type(ValueError())
False
>>> type(KeyError) == type(ValueError)
True

but later I realised I am inside a bad pattern, I was catching and exception with except and raising it again with raise.