Skip to content
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

pytest.warn doesn't appear to be working for deprecation warnings #1026

Closed
alex opened this issue Sep 19, 2015 · 6 comments
Closed

pytest.warn doesn't appear to be working for deprecation warnings #1026

alex opened this issue Sep 19, 2015 · 6 comments
Labels
status: help wanted developers would like help from experts on this topic type: docs documentation improvement, missing or needing clarification
Milestone

Comments

@alex
Copy link
Contributor

alex commented Sep 19, 2015

I'm not sure what to make of this, but it appears to be failing on a very simple test:

(tempenv-6cb925871591c) ~/.v/tempenv-6cb925871591c $ cat t.py
import warnings

import pytest


def test_foo():
    with pytest.warns(PendingDeprecationWarning):
        warnings.warn("msg", PendingDeprecationWarning)
(tempenv-6cb925871591c) ~/.v/tempenv-6cb925871591c $ py.test t.py
====================================================== test session starts =======================================================
platform darwin -- Python 2.7.10, pytest-2.8.0, py-1.4.30, pluggy-0.3.1
rootdir: /Users/alex_gaynor/.virtualenvs/tempenv-6cb925871591c, inifile:
collected 1 items

t.py F

============================================================ FAILURES ============================================================
____________________________________________________________ test_foo ____________________________________________________________

    def test_foo():
        with pytest.warns(PendingDeprecationWarning):
>           warnings.warn("msg", PendingDeprecationWarning)
E           Failed: DID NOT WARN

t.py:8: Failed
==================================================== 1 failed in 0.01 seconds ====================================================
@RonnyPfannschmidt RonnyPfannschmidt added the type: bug problem that needs to be addressed label Sep 19, 2015
@RonnyPfannschmidt RonnyPfannschmidt added this to the 2.8.1 milestone Sep 19, 2015
@The-Compiler
Copy link
Member

This is because Python ignores DeprecationWarning and PendingDeprecationWarning by default, so in fact there is no warning above.

Your above snippet works fine when using warnings.simplefilter("always"), so I think everything works like it should.

@RonnyPfannschmidt
Copy link
Member

after reconsidering, its not a bug on our side, see #1032 for a potential help

we should document that detail

@RonnyPfannschmidt RonnyPfannschmidt added status: help wanted developers would like help from experts on this topic type: docs documentation improvement, missing or needing clarification and removed type: bug problem that needs to be addressed labels Sep 21, 2015
@RonnyPfannschmidt RonnyPfannschmidt changed the title pytest.warn doesn't appear to be working? pytest.warn doesn't appear to be working for deprecation warnings Sep 21, 2015
@Akasurde
Copy link
Contributor

@RonnyPfannschmidt I would like to help in this.

@nicoddemus
Copy link
Member

@Akasurde on documenting the detail about DeprecationWarning?

@Akasurde
Copy link
Contributor

@RonnyPfannschmidt Yes, I would like to help on documenting. Let me know details about this.

@nicoddemus
Copy link
Member

Opening a PR with the appropriate changes in the docs is the way to go (you can even do this directly from the GitHub interface). We are planning on a 2.8.1 release real soon (probably Monday), so now would be a good time to get this in. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted developers would like help from experts on this topic type: docs documentation improvement, missing or needing clarification
Projects
None yet
Development

No branches or pull requests

5 participants