diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 091d66794e5..ab13758cc3a 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -1044,10 +1044,9 @@ def test_read_byte_attrs_as_unicode(self): with create_tmp_file() as tmp_file: with nc4.Dataset(tmp_file, 'w') as nc: nc.foo = b'bar' - actual = open_dataset(tmp_file) - expected = Dataset(attrs={'foo': 'bar'}) - self.assertDatasetIdentical(expected, actual) - actual.close() + with open_dataset(tmp_file) as actual: + expected = Dataset(attrs={'foo': 'bar'}) + self.assertDatasetIdentical(expected, actual) def test_encoding_unlimited_dims(self): ds = Dataset({'x': ('y', np.arange(10.0))})