Skip to content
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

Test for warnings fail when using old version of pytest #2337

Closed
shoyer opened this issue Aug 2, 2018 · 2 comments
Closed

Test for warnings fail when using old version of pytest #2337

shoyer opened this issue Aug 2, 2018 · 2 comments

Comments

@shoyer
Copy link
Member

shoyer commented Aug 2, 2018

Some of our tests for warnings currently fail when run using an old version of pytest. The problem appears to be that we rely on pytest.warns() accepting subclasses rather exact matches.

This was fixed upstream in pytest (pytest-dev/pytest#2166), but we still should specify the more specific warning types in xarray.

=================================== FAILURES ===================================
_________________ TestEncodeCFVariable.test_missing_fillvalue __________________

self = <xarray.tests.test_conventions.TestEncodeCFVariable testMethod=test_missing_fillvalue>

    def test_missing_fillvalue(self):
        v = Variable(['x'], np.array([np.nan, 1, 2, 3]))
        v.encoding = {'dtype': 'int16'}
        with pytest.warns(Warning, match='floating point data as an integer'):
>           conventions.encode_cf_variable(v)
E           Failed: DID NOT WARN

tests/test_conventions.py:89: Failed

________________________________ TestAlias.test ________________________________

self = <xarray.tests.test_utils.TestAlias testMethod=test>

    def test(self):
        def new_method():
            pass
        old_method = utils.alias(new_method, 'old_method')
        assert 'deprecated' in old_method.__doc__
        with pytest.warns(Warning, match='deprecated'):
>           old_method()
E           Failed: DID NOT WARN

tests/test_utils.py:28: Failed

___________________ TestIndexVariable.test_coordinate_alias ____________________

self = <xarray.tests.test_variable.TestIndexVariable testMethod=test_coordinate_alias>

    def test_coordinate_alias(self):
        with pytest.warns(Warning, match='deprecated'):
>           x = Coordinate('x', [1, 2, 3])
E           Failed: DID NOT WARN

tests/test_variable.py:1752: Failed
__________________________ TestAccessor.test_register __________________________

self = <xarray.tests.test_extensions.TestAccessor testMethod=test_register>

    def test_register(self):
    
        @xr.register_dataset_accessor('demo')
        @xr.register_dataarray_accessor('demo')
        class DemoAccessor(object):
            """Demo accessor."""
    
            def __init__(self, xarray_obj):
                self._obj = xarray_obj
    
            @property
            def foo(self):
                return 'bar'
    
        ds = xr.Dataset()
        assert ds.demo.foo == 'bar'
    
        da = xr.DataArray(0)
        assert da.demo.foo == 'bar'
    
        # accessor is cached
        assert ds.demo is ds.demo
    
        # check descriptor
        assert ds.demo.__doc__ == "Demo accessor."
        assert xr.Dataset.demo.__doc__ == "Demo accessor."
        assert isinstance(ds.demo, DemoAccessor)
        assert xr.Dataset.demo is DemoAccessor
    
        # ensure we can remove it
        del xr.Dataset.demo
        assert not hasattr(xr.Dataset, 'demo')
    
        with pytest.warns(Warning, match='overriding a preexisting attribute'):
            @xr.register_dataarray_accessor('demo')
>           class Foo(object):
E           Failed: DID NOT WARN

tests/test_extensions.py:60: Failed

@max-sixty
Copy link
Collaborator

Can we close this given the updated pytest has been out for two years?

(though in general ofc we should test for the more specific warning)

@shoyer shoyer closed this as completed Nov 12, 2019
@shoyer
Copy link
Member Author

shoyer commented Nov 12, 2019

agreed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants