Skip to content

python.raises examples are unclear #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pytestbot opened this issue Sep 8, 2014 · 1 comment
Closed

python.raises examples are unclear #586

pytestbot opened this issue Sep 8, 2014 · 1 comment
Labels
type: docs documentation improvement, missing or needing clarification type: enhancement new feature or API change, should be merged into features branch

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Laszlo Papp (BitBucket: lpapp_polatis, GitHub: lpapp_polatis)


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.


@pytestbot
Copy link
Contributor Author

Original comment by Floris Bruynooghe (BitBucket: flub, GitHub: flub):


Improve pytest.raises examples

Fixes issue #586.

@pytestbot pytestbot added type: enhancement new feature or API change, should be merged into features branch type: docs documentation improvement, missing or needing clarification labels Jun 15, 2015
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Jun 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: docs documentation improvement, missing or needing clarification type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

1 participant