GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Warning integration breaks warnings.filterwarnings · Issue #2430 · pytest-dev/pytest

Warning integration breaks warnings.filterwarnings #2430

New issue
Copy link
New issue
Copy link
Closed
#2445
psf/requests
#4056
psf/requests#4056
Closed
Warning integration breaks warnings.filterwarnings#2430
#2445
psf/requests
#4056
Copy link
Labels
plugin: warningsrelated to the warnings builtin plugintype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

Description

@zzzeek
zzzeek
opened on May 23, 2017
Issue body actions

SQLAlchemy CI is now broken due to the unconditional inclusion of pytest-warnings in py.test 3.1.0. I need at least to know how to disable this plugin entirely.

In our test suite we make use of the warnings filter internally in order to propagate our own warnings to errors. It seems like warnings.filter() is now non-functional when this plugin is installed.

Demo test case:

import warnings

class MyWarning(Warning):
    pass

warnings.filterwarnings("error", category=MyWarning)

class TestWarnings(object):
    def test_my_warning(self):
        try:
            warnings.warn(MyWarning("warn!"))
            assert False
        except MyWarning:
            assert True


with py.test 3.0.7:


$ py.test test_warning.py 
======================================================== test session starts ========================================================
platform linux2 -- Python 2.7.13, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /home/classic/Desktop/tmp, inifile:
plugins: xdist-1.15.0, cov-2.4.0
collected 1 items 

test_warning.py .

===================================================== 1 passed in 0.01 seconds ======================================================

with py.test 3.1.0:

$ py.test test_warning.py 
======================================================== test session starts ========================================================
platform linux2 -- Python 2.7.13, pytest-3.1.0, py-1.4.33, pluggy-0.4.0
rootdir: /home/classic/Desktop/tmp, inifile:
plugins: xdist-1.15.0, cov-2.4.0
collected 1 items 

test_warning.py F

============================================================= FAILURES ==============================================================
___________________________________________________ TestWarnings.test_my_warning ____________________________________________________

self = <test_warning.TestWarnings object at 0x7fecb08a5290>

    def test_my_warning(self):
        try:
            warnings.warn(MyWarning("warn!"))
>           assert False
E           assert False

test_warning.py:12: AssertionError
========================================================= warnings summary ==========================================================
test_warning.py::TestWarnings::()::test_my_warning
  /home/classic/Desktop/tmp/test_warning.py:11: MyWarning: warn!
    warnings.warn(MyWarning("warn!"))

-- Docs: http://doc.pytest.org/en/latest/warnings.html
=============================================== 1 failed, 1 warnings in 0.03 seconds ================================================

I have tried everything I can think of with the new -W flag, disable-warnings, no luck.

Please advise on the correct options to allow Python stdlib warnings.filter() to work again, thanks!

Activity

Next
  1. zzzeek
    added 2 commits that reference this issue on May 23, 2017

    - pin py.test at 3.0.7 due to pytest-dev/pytest#2430

    fe28123

    - pin py.test at 3.0.7 due to pytest-dev/pytest#2430

    eed7888
  2. The-Compiler
    changed the title [-]forcing pytest-warnings breaks the world[/-] [+]Warning integration breaks warnings.filterwarnings[/+] on May 23, 2017
  3. zzzeek commented on May 23, 2017

    @zzzeek
    zzzeek
    on May 23, 2017
    Author
    More actions

    how do I get a helper to help triage my bugs and change nasty headlines to nice ones? :(

  4. nicoddemus commented on May 23, 2017

    @nicoddemus
    nicoddemus
    on May 23, 2017
    Member
    More actions

    SQLAlchemy CI is now broken due to the unconditional inclusion of pytest-warnings in py.test 3.1.0. I need at least to know how to disable this plugin entirely.

    @zzzeek you can disable the warnings plugin by passing -p no:warnings; this will disable the plugin completely and you should get green builds again. You can choose to add this to your pytest.ini file:

    [pytest]
    addopts = -p no:warnings

    As for the problem itself, I will take a more careful look later.

    Reacted by Hong Minhee (洪 民憙), Oliver Bestwalter and Taine Zhao
  5. nicoddemus
    added
    type: bugproblem that needs to be addressed
    type: regressionindicates a problem that was introduced in a release which was working previously
    on May 23, 2017
  6. zzzeek commented on May 23, 2017

    @zzzeek
    zzzeek
    on May 23, 2017
    Author
    More actions

    great, thanks!

  7. zzzeek
    added 2 commits that reference this issue on May 23, 2017

    - add option to disable py.test warnings plugin;

    a987942

    - add option to disable py.test warnings plugin;

    40b74df
  8. RonnyPfannschmidt commented on May 23, 2017

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on May 23, 2017
    Member
    More actions

    i believe https://github.com/pytest-dev/pytest/blob/master/_pytest/warnings.py#L54 is gutting all prior setups

    we should just call reset_warning instead when we do something like that and give people a opt-out to allow respecting in code specifications

  9. nicoddemus commented on May 24, 2017

    @nicoddemus
    nicoddemus
    on May 24, 2017
    Member
    More actions

    @zzzeek thanks for posting the example, it helped understand the issue.

    Can I ask why you add that warnings filter? If the objective is to turn certain warnings into errors, you can now configure your pytest.ini to the same effect. Raising more awareness about warnings was the motivation for this new feature.

    Also, do you think we should add a blurb to the warnings docs making it easy for users to find how to disable it in case they run into trouble?

    @RonnyPfannschmidt

    i believe https://github.com/pytest-dev/pytest/blob/master/_pytest/warnings.py#L54 is gutting all prior setups

    Actually the implementation uses catch_warnings, which saves the previous filters and restores them after the call (see https://github.com/python/cpython/blob/master/Lib/warnings.py#L454). Unfortunately this has the effect of silencing errors configured manually by other warnings.simplefilter calls, which is the heart of this issue. Also, by default Python will install a number of default filters silencing DeprecationWarnings, ImportWarnings and others, which are precisely the kind of warnings we believe should be displayed in test suites.

    @RonnyPfannschmidt

    we should just call reset_warning instead when we do something like that

    resetwarnings() will actually throw out all filters:

    (https://docs.python.org/3/library/warnings.html#warnings.resetwarnings)

    This discards the effect of all previous calls to filterwarnings(), including that of the -W command line options and calls to simplefilter().

    Which is not what we want, I think.

    I'm not sure how to proceed here, so I would like to hear some opinions.

  10. RonnyPfannschmidt commented on May 24, 2017

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on May 24, 2017
    Member
    More actions

    @nicoddemus pushing a new once simple filter is invalidating all other filter s due to matching first
    so its literally pushing a new filter to be there

    i beleive that by pushing a unfiltered once for all warning setups literally breaks all expectations,
    people should opt in into breaking filter changes, not have to opt out

    in retrospect the warnings addition is implemented in a way that warrants a major release, and the way we should fix it warrants a major release as well because to fix this issue we need to do a breaking change, and we never adopted a process of publishing experiments that we may change our mind on

  11. shoyer
    added a commit that references this issue on May 24, 2017

    Fix errors in the test suite due to pytest warning changes

    1b94260
  12. nicoddemus commented on May 24, 2017

    @nicoddemus
    nicoddemus
    on May 24, 2017
    Member
    More actions

    pushing a new once simple filter is invalidating all other filter s due to matching first
    so its literally pushing a new filter to be there

    True... it does have an append option though, so perhaps we should change it to append=True to add it to the end of the list. The drawback of this is that the default warnings filter that hide DeprecatedWarning, ImportWarning and etc will be active and hide those warnings by default.

    Perhaps we should add two filters, a once filter to the end of the lists and a filter to show some selected warnings (DeprecatedWarning, ImportWarning) to the beginning of the list? After writing this I just realized though: someone might have configured a filter for DeprecatedWarning (for example) to error out, in which case we might again break some test suite which relies on that.

  13. 23 remaining items

  14. nicoddemus
    added a commit that references this issue on May 26, 2017

    Warn that warning-capture can break existing suites in the docs and C…

    313a884
  15. okken commented on May 26, 2017

    @okken
    okken
    on May 26, 2017
    Contributor
    More actions

    Having a warning system is hugely useful.
    Defaulting to all warnings on is not.

    Even if everyone decides to leave this feature in, it's broken.
    Only reasonable course of action is to back it out until it's more thoroughly tested.ASAP

    1. This code shows a warning that should not be on by default:

    test_something.py

    class TestHelper():
      def __init__(self):
        pass
    
      def someNonTestStuff(self):
        pass
    
    (venv) $ pytest test_something.py 
    ========================== test session starts ==========================
    platform darwin -- Python 3.6.1, pytest-3.1.0, py-1.4.33, pluggy-0.4.0
    rootdir: /Users/okken/foo, inifile:
    collected 0 items 
    
    =========================== warnings summary ============================
    test_something.py::TestHelper
      cannot collect test class 'TestHelper' because it has a __init__ constructor
    
    -- Docs: http://doc.pytest.org/en/latest/warnings.html
    ====================== 1 warnings in 0.00 seconds =======================
    

    2. --strict doesn't work

    (venv) $ pytest --help
    ...
      --strict              run pytest in strict mode, warnings become errors
    ...
    
    (venv) $ pytest --strict test_something.py 
    ========================== test session starts ==========================
    platform darwin -- Python 3.6.1, pytest-3.1.0, py-1.4.33, pluggy-0.4.0
    rootdir: /Users/okken/projects/book/bopytest/Book/code/foo, inifile:
    collected 0 items 
    
    =========================== warnings summary ============================
    test_something.py::TestHelper
      cannot collect test class 'TestHelper' because it has a __init__ constructor
    
    -- Docs: http://doc.pytest.org/en/latest/warnings.html
    ====================== 1 warnings in 0.01 seconds =======================
    
    
    Reacted by Michael Bayer
  16. nicoddemus
    added
    plugin: warningsrelated to the warnings builtin plugin
    on May 29, 2017
  17. nicoddemus
    added a commit that references this issue on May 29, 2017

    Make warnings plugin opt-in

    This issue will close once commit 4b858ab is merged into the 'main' branch.
    4b858ab
  18. nicoddemus commented on May 29, 2017

    @nicoddemus
    nicoddemus
    on May 29, 2017
    Member
    More actions

    Hi everyone,

    After a discussion on the mailing list the team decided to release 3.2.0 with the new plugin being opt-in instead of being active by default (#2443).

    Again we apologize for the problems many of you had; it was not our intention in the least. We just did not foresee that the new plugin could break some test suites, otherwise we would have never released it active by default.

    If all goes well, we should see a new release later today or tomorrow.

    Thanks everyone for their feedback and understanding! 👍

  19. nicoddemus commented on May 29, 2017

    @nicoddemus
    nicoddemus
    on May 29, 2017
    Member
    More actions

    @okken

    This code shows a warning that should not be on by default:

    Hi Brian, just now saw this sorry. Actually that warning should appear by default because it helps users realize why that test class is not being collected; in fact if I'm not mistaken that warning already appears in pytest 3.0.

    --strict doesn't work

    Definitely, opened a new issue for it: #2444.

  20. nicoddemus
    added 6 commits that reference this issue on May 29, 2017

    No longer mess with warning filters during warnings capture

    This issue will close once commit 5e243a1 is merged into the 'main' branch.
    5e243a1

    No longer override existing warning filters during warnings capture

    This issue will close once commit babb783 is merged into the 'main' branch.
    babb783

    No longer override existing warning filters during warnings capture

    This issue will close once commit c6774cc is merged into the 'main' branch.
    c6774cc

    No longer override existing warning filters during warnings capture

    This issue will close once commit db8d83a is merged into the 'main' branch.
    db8d83a

    No longer override existing warning filters during warnings capture

    This issue will close once commit f591c6d is merged into the 'main' branch.
    f591c6d

    No longer override existing warning filters during warnings capture

    This issue will close once commit 32e2642 is merged into the 'main' branch.
    32e2642
  21. nicoddemus
    closed this as completedin #2445on May 30, 2017
  22. myroslav
    added a commit that references this issue on Sep 17, 2024

    Disable pytest-warnings which cause random test failures.

    cd7683f
  23. kvanrens1
    added a commit that references this issue on Mar 14, 2025

    Disable pytest-warnings which cause random test failures.

    1fc5652
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: warningsrelated to the warnings builtin plugintype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.