-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Warning integration breaks warnings.filterwarnings #2430
Comments
Change-Id: I587282da141aa6ea92f944eeb4c9e5782d0b5f29 (cherry picked from commit eed7888)
Change-Id: I587282da141aa6ea92f944eeb4c9e5782d0b5f29
how do I get a helper to help triage my bugs and change nasty headlines to nice ones? :( |
@zzzeek you can disable the warnings plugin by passing [pytest]
addopts = -p no:warnings As for the problem itself, I will take a more careful look later. |
great, thanks! |
lift cap on py.test. references: pytest-dev/pytest#2430 Change-Id: Ieb8a6258ba1d15efa570d9cda2b51cf021499a23
lift cap on py.test. references: pytest-dev/pytest#2430 Change-Id: Ieb8a6258ba1d15efa570d9cda2b51cf021499a23 (cherry picked from commit a987942)
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 |
@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 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?
Actually the implementation uses
(https://docs.python.org/3/library/warnings.html#warnings.resetwarnings)
Which is not what we want, I think. I'm not sure how to proceed here, so I would like to hear some opinions. |
@nicoddemus pushing a new once simple filter is invalidating all other filter s due to matching first i beleive that by pushing a unfiltered once for all warning setups literally breaks all expectations, 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 |
This is causing CI failures for some builds. This is really a pytest bug (pytest-dev/pytest#2430), but working around this on our end is easy enough (and cleans things up a little).
True... it does have an Perhaps we should add two filters, a |
we simply should not do anying per default |
any choice we make breaks some peoples expectations, we should jsut let the people decide |
I don't think hiding warnings by default is a good behavior for a test runner - don't all other test runners show them by default too? How do they solve that problem? |
@The-Compiler this is not about showing vs hiding, but about not altering the warnings subsystem unless requested python warnings are inherently state-full, and people register different actions for different warnings note that warnings are not hidden by default, but library authors may choose to hide/error on certain errors, or decide to show some errors only once changing those behaviours inwarranted breaks code |
Python does hide DeprecationWarnings (and some others?) by default, because it doesn't want to confront users with those when they're simply using a library. Test runners should turn them on (like unittest.py does too), so they aren't simply ignored. |
* Fix errors in the test suite due to pytest warning changes This is causing CI failures for some builds. This is really a pytest bug (pytest-dev/pytest#2430), but working around this on our end is easy enough (and cleans things up a little). * deprecated_call() -> warns(FutureWarning) * another attempt
so the first reason we add the warnings filter is because any SAWarnings, e.g. those generated by SQLAlchemy, should never occur without us adding directives that we expect them - so these all go to "error" by default, they need to raise. The next reason we use "error" is that a lot of the older tests ensure that particular code emits warnings by doing an assertRaises() style of check, taking advantage of the fact that the SAWarnings all raise. In order to accommodate for code that expects to emit SAWarning but we don't care, there are function decorators like Building on that approach, the new style of writing tests that's expected to emit warnings is that we have a context manager "with expect_warnings(*strings)" that manipulates the warnings filter within the block to allow warnings that match our strings to go through, to assert that they were actually seen else fail the test, and to have all other SAWarnings coninue to raise exceptions. These last use cases require the use of highly specific set of filter operations that could not be sufficiently addressed by flags in "pytest.ini / setup.cfg". I also agree with the argument that py.test should try not to make changes that interfere with existing approaches. Whlie we could move our global "warnings" filter to be omitted under a py.test run and instead rely upon py.test specific settings, this makes our test suite more complicated as the sutie is constructed to have a layer of indirection between which testing framework is in use. While SQLAlchemy makes extensive use of py.test features, the dependencies on these features is contained entirely within a plugin-oriented module that invokes only when the "py.test" command is used. You can still run our tests with nose. The rationale for this is not that anyone uses nose anymore, but rather that nobody uses nose anymore - a reminder that after I and other developers spent many months converting our test suite to use nose, nose within a couple of years went unmaintained and I had to pick up and start all over again with py.test. Therefore while I love py.test, I keep its featureset at arm's length and nothing within the tests themselves refer to py.test. our test suite is always ready to accommodate other test runners should that need ever arise. |
to be fair, while older SQLAlchemy versions were using ad-hoc filterwarnings() in order to get the "per-test warnings filter" behavior, currently we're just mock.patching warnings.warn() to make it simple. |
We may be able to remove this if pytest resolves pytest-dev/pytest#2430
We may be able to remove this if pytest resolves pytest-dev/pytest#2430
@The-Compiler unittest defaults to DONT DO ANYTHING - see https://github.com/python/cpython/blob/v3.6.1/Lib/unittest/runner.py#L159 |
Definitely agree. But looking at how
We didn't expect the introduction to break existing suites, and for that we apologize. We try our best to ensure we don't break existing suites in minor releases, but this went out in 3.1 and I'm not sure if rolling the change back (or defaulting it to opt-in) in a new 3.2 release would help, because by this point I suspect most people who had trouble with warnings has already disabled the internal plugin. |
Does your test suite deal with the |
@zzzeek just curious: in your opinion, if you were to embrace the new pytest warnings feature in 3.1 by throwing away your customization would that improve the test suite? Would that be relatively simple to do? Just as a thought exercise, disregarding your point about having a layer over the test runner. I'm under the impression that the new plugin will be a problem in cases where the test suite implements/customizes its own handling of warnings and that creates clashes. In this case it might be better to just disable the plugin to keep things working, but users might consider to throw away their own customizations and use the built in features. |
The test that randomly fails is at https://bitbucket.org/openpyxl/openpyxl/src/44212297981845d4cfad77e879b812ebd2d7171e/openpyxl/reader/tests/test_worksheet.py?at=2.4&fileviewer=file-view-default#test_worksheet.py-470 I don't have many tests that check for warnings so it's not too much work to change them but this change did trip me up. The new context manager looks nicer than |
@nicoddemus if i werent using py.test, and i had a simple test suite where we just want our own warnings to raise an error and for all python deprecation stuff to emit, then setting up a configuration level would be more palatable, although even then, a filter that wants to ensure a certain class of warnings is errored is still IMO a little better expressed in code rather than config since it refers to a class that's part of the library being tested. next, if my test suite needed to do per-test alterations to the warnings filter so that we can assert or ignore various warnings, that has to be done in code w/ decorators, context managers. so if the feature here only allows config-level flags, that's not sufficient in any case. |
Indeed, we should make that more obvious in the docs. |
This is a very valid point, thanks. This seems like a feature request though, would you like to create a new issue for it so we can track it? |
…HANGELOG Related to discussion in pytest-dev#2430
Having a warning system is hugely useful. Even if everyone decides to leave this feature in, it's broken. 1. This code shows a warning that should not be on by default: test_something.py
2. --strict doesn't work
|
Hi everyone, After a discussion on the mailing list the team decided to release 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! 👍 |
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.
Definitely, opened a new issue for it: #2444. |
See pytest-dev/pytest#2430 --HG-- branch : 2.4
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:
with py.test 3.0.7:
with py.test 3.1.0:
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!
The text was updated successfully, but these errors were encountered: