RSS Amplifier

jml :: Jonathan Lange · Aug 13, 2014

Isn't it Pythonic?

0
Sign in to vote or save

Jonathan Lange · jml :: Jonathan Lange

·1 min

I really should be over this by now.

Here’s how you test exceptions in Python 2.7 and later:

:::python
with self.assertRaises(SomeException) as cm:
    do_something()
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)

(as recommended in the unittest documentation)

Here’s how you test exceptions in earlier Pythons, using libraries like testtools.

:::python
the_exception = self.assertRaises(SomeException, do_something)
self.assertEqual(the_exception.error_code, 3)

I still like the second way. It’s simpler, uses less code, and doesn’t rely on new syntax. I’m sorry it didn’t work out that way.

I guess this is how Barry feels about the diamond operator.

Read the original on jml.io

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.