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
_______________________________________________
pytest-commit mailing list
pytest-commit@python.org
https://mail.python.org/mailman/listinfo/pytest-commit

Reply via email to