[Pytest-commit] Issue #586: python.raises examples are unclear (hpk42/pytest)
Laszlo Papp
issues-reply at bitbucket.org
Mon Sep 8 15:22:36 CEST 2014
New issue 586: python.raises examples are unclear
https://bitbucket.org/hpk42/pytest/issue/586/pythonraises-examples-are-unclear
Laszlo Papp:
>From the following page:
http://pytest.org/latest/assert.html
```
#!python
import pytest
with pytest.raises(ZeroDivisionError):
1 / 0
```
and
```
#!python
with pytest.raises(RuntimeError) as excinfo:
def f():
f()
f()
# do checks related to excinfo.type, excinfo.value, excinfo.traceback
```
My first thoughts have been:
* Is it really a good idea to use global "with" context management here?
* If yes, because it is better to wrap the 'f' function around in one place rather than at each call, why is it not done like a decorator, nicely?
But then, I was enlightened that this ought to be inside a test function, yet it has not been clear to me, especially since the former example was right after an import. Yes, I am aware of that import can happen anywhere in python, but it was not my first thought that pytest would be imported somewhere in a test function rather than outside "globally".
I think it would be nice to make these examples a bit clearer.
Responsible: flub
More information about the pytest-commit
mailing list