html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/pull/6251#issuecomment-1033137904,https://api.github.com/repos/pydata/xarray/issues/6251,1033137904,IC_kwDOAMm_X849lG7w,10194086,2022-02-08T22:46:00Z,2022-02-08T22:46:00Z,MEMBER,"Nice suggestion. How about `assert_no_warnings`? Not sure if `supress_warnings` is a bit over the top?
```python
from contextlib import contextmanager
import warnings
@contextmanager
def assert_no_warnings():
with warnings.catch_warnings(record=True) as record:
yield
assert len(record) == 0, ""got unexpected warning(s)""
@contextmanager
def supress_warnings(*messages):
messages = ("""",) if not messages else messages
with warnings.catch_warnings():
for message in messages:
warnings.filterwarnings(""ignore"", message)
yield
```
```python
with supress_warnings():
warnings.warn(""test"")
with supress_warnings(""test""):
warnings.warn(""test"")
with supress_warnings(""not test"", ""something else""):
warnings.warn(""test"")
with assert_no_warnings():
pass
with assert_no_warnings():
warnings.warn(""test"")
```
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1126086052
https://github.com/pydata/xarray/pull/6251#issuecomment-1033105848,https://api.github.com/repos/pydata/xarray/issues/6251,1033105848,IC_kwDOAMm_X849k_G4,14808389,2022-02-08T22:02:29Z,2022-02-08T22:02:29Z,MEMBER,"what do you think about adding `no_warnings()` and `suppress_warnings()` to `xarray.tests.__init__`? For those `pytest` [recommends](https://docs.pytest.org/en/7.0.x/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests)
```python
# no_warnings
with warnings.catch_warnings():
warnings.simplefilter(""error"")
...
# or, without the stacktrace
with warnings.catch_warnings(record=True) as record:
...
assert len(record) == 0
# or, with `pytest.warns()`
with pytest.warns() as record:
...
assert len(record) == 0
# suppress
with warnings.catch_warnings():
warnings.simplefilter(""ignore"")
...
```
but those can easily get a name and be a bit easier to read. E.g. for the version of `no_warnings()` used in this PR:
```python
@contextmanager
def no_warnings():
with warnings.catch_warnings(record=True) as record:
yield
assert len(record) == 0
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1126086052
https://github.com/pydata/xarray/pull/6251#issuecomment-1033100203,https://api.github.com/repos/pydata/xarray/issues/6251,1033100203,IC_kwDOAMm_X849k9ur,5635139,2022-02-08T21:55:45Z,2022-02-08T21:55:45Z,MEMBER,Thanks @mathause ! LGTM,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1126086052
https://github.com/pydata/xarray/pull/6251#issuecomment-1033075245,https://api.github.com/repos/pydata/xarray/issues/6251,1033075245,IC_kwDOAMm_X849k3ot,10194086,2022-02-08T21:23:21Z,2022-02-08T21:23:21Z,MEMBER,close/ reopen,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1126086052