[pytest-dev] [3.1 feature] "assert not raise exception" helper: opinions about the name
Ronny Pfannschmidt
opensource at ronnypfannschmidt.de
Wed Apr 5 11:49:24 EDT 2017
i meant the except clause
In [1]: try:
...: 1/0
...: except None:
...: pass
...:
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-1-0d5ef3af74e6> in <module>()
1 try:
----> 2 1/0
3 except None:
4 pass
ZeroDivisionError: integer division or modulo by zero
vs
In [1]: try:
...: 1/0
...: except None:
...: pass
...:
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-1-0d5ef3af74e6> in <module>()
1 try:
----> 2 1/0
3 except None:
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-1-0d5ef3af74e6> in <module>()
1 try:
2 1/0
----> 3 except None:
4 pass
TypeError: catching classes that do not inherit from BaseException is
not allowed
On 05.04.2017 17:46, Florian Bruhin wrote:
> Hey,
>
> On Wed, Apr 05, 2017 at 05:25:01PM +0200, Ronny Pfannschmidt wrote:
>> while experimenting i learned of the fun fact that None is a "valid
>> exception type"
>> for except clauses on at least python 2.7
> But it doesn't seem to be possible to raise it:
>
> Python 2.7.13 (default, Dec 21 2016, 07:16:46)
> >>> raise None
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: exceptions must be old-style classes or derived from BaseException, not NoneType
>
> Florian
>
More information about the pytest-dev
mailing list