question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FR: Revert pytest.warns(None) changes

See original GitHub issue

What’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

https://github.com/statsmodels/statsmodels/blob/948bfc4520791b2d867829259367f446bd107218/statsmodels/tsa/vector_ar/tests/test_var_jmulti.py#L133-L139

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bashtagecommented, Dec 10, 2021

@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.

Unfortunately this is off the table, because it would be a backwards-incompatible change compared to both the current and pre-deprecation behaviour (when passing None effectively disabled the check entirely).

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 of None couldn’t be made to be no warning, as many thing it is, and pytest.raises(Warning) could be made to raise any warning.

0reactions
nicoddemuscommented, Dec 10, 2021
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found