FR: Revert pytest.warns(None) changes
See original GitHub issueWhat’s the problem this feature will solve?
I need to dynamically catch warnings where whether the warning is issued or not depends on information that is only available at runtime.
Describe the solution you’d like
Accept pytest.warns(None)
as equivalent to pytest.warns()
without error
warn_typ = FutureWarning if dt_s_tup[0] == "nc" else None
model = VAR(endog, exog)
with pytest.warns(warn_typ):
results_per_deterministic_terms[dt_s_tup] = model.fit(
maxlags=4, trend=dt_s_tup[0], method="ols"
)
from
Alternative Solutions
I don’t see any workaround. As far as I know there is not easy way to work around this. Is the solution to use an empty *args expansion?
This removal seems to have missed the relative challenge of calling a function with 1 argument vs 0 arguments.
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
pytest warnings due to deprecation of pytest.warns(None)
Pytest issues warnings about using pytest.warns(None) context manager, where the None part is now being deprecated. For example,
Read more >Deprecations and Removals — pytest documentation
pytest.warns(None) is now deprecated because it was frequently misused. Its correct usage was checking that the code emits at least one warning of...
Read more >How to use pytest to assert NO Warning is raised
For example pytest. warns(FutureWarning): pass fails since no FutureWarning was thrown. FYI: pytest. warns(None) is deprecated in pytest 7.0.
Read more >SciPy 1.8.0 Release Notes — SciPy v1.9.3 Manual
There have been a number of deprecations and API changes in this release, which are documented ... #15186: Fix use of `pytest.warns(None)` for...
Read more >Python pytest - The Blue Book
Inside tests it's possible to change the log level for the captured log messages. ... with pytest.warns(UserWarning, match='must be 0 or None'): ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Zac-HD We can’t run with -Werror because of past sins and far too many warnings int he test suite, so that isn’t viable. It would be a big improvement if there was an API way to pass a value that would indicate whether there is no error expected rather than no value for this case and a value in other cases. It ultimately makes for hard to write code. Similarly with the idea of
pytest.does_not_raise()
which can’t be used at runtime in a sane way when code might process a warning under some circumstance but not others in parameterized tests.As far as I can see the pending change is also backward incompatible since it will raise an error for
pytest.raises(None)
, so I don’t see any fundamental reason why the behavior ofNone
couldn’t be made to be no warning, as many thing it is, andpytest.raises(Warning)
could be made to raise any warning.Please see https://github.com/pytest-dev/pytest/issues/9404.