Repository: pydata/xarray

Issue:
dask ImportWarning causes pytest failure
#### Code Sample, a copy-pastable example if possible

```bash
# Your code here
pytest -v xarray/tests/test_backends.py::NetCDF4DataTest
```
#### Problem description

Instead of passing all tests, this fails on the `test_88_character_filename_segmentation_fault` function. 

```
E               AssertionError: exception ImportWarning("can't resolve package from __spec__ or __package__, falling back on __name__ and __path__",) did not match pattern 'segmentation fault'
```

It oddly doesn't seem to be related to the 88 character issue. I traced this down to xarray/backends/common.py::get_scheduler where an "ImportWarning" is not being caught on line 49.  

#### Expected Output

Passes all tests. Adding ImportWarning to the tuple of exceptions in get_scheduler fixes the problem.

#### Output of ``xr.show_versions()``

<details>
# Paste the output here xr.show_versions() here
>>> xr.show_versions()
/Users/barronh/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Darwin
OS-release: 17.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

xarray: 0.10.2
pandas: 0.22.0
numpy: 1.14.2
scipy: 1.0.0
netCDF4: 1.3.1
h5netcdf: None
h5py: 2.7.1
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.17.1
distributed: 1.21.3
matplotlib: 2.2.2
cartopy: None
seaborn: 0.8.1
setuptools: 38.4.0
pip: 9.0.1
conda: 4.5.0
pytest: 3.4.2
IPython: 6.2.1
sphinx: 1.6.6
</details>


Discussion:

Patch:
diff --git a/xarray/backends/netCDF4_.py b/xarray/backends/netCDF4_.py
index 28aa4dbd..89a0e72e 100644
--- a/xarray/backends/netCDF4_.py
+++ b/xarray/backends/netCDF4_.py
@@ -264,13 +264,13 @@ class NetCDF4DataStore(WritableCFDataStore, DataStorePickleMixin):
         if (len(filename) == 88 and
                 LooseVersion(nc4.__version__) < "1.3.1"):
             warnings.warn(
-                '\nA segmentation fault may occur when the\n'
-                'file path has exactly 88 characters as it does\n'
-                'in this case. The issue is known to occur with\n'
-                'version 1.2.4 of netCDF4 and can be addressed by\n'
-                'upgrading netCDF4 to at least version 1.3.1.\n'
-                'More details can be found here:\n'
-                'https://github.com/pydata/xarray/issues/1745  \n')
+                'A segmentation fault may occur when the '
+                'file path has exactly 88 characters as it does '
+                'in this case. The issue is known to occur with '
+                'version 1.2.4 of netCDF4 and can be addressed by '
+                'upgrading netCDF4 to at least version 1.3.1. '
+                'More details can be found here: '
+                'https://github.com/pydata/xarray/issues/1745')
         if format is None:
             format = 'NETCDF4'
         opener = functools.partial(_open_netcdf4_group, filename, mode=mode,


Test patch:
diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py
index 0bef13a8..e0f03036 100644
--- a/xarray/tests/test_backends.py
+++ b/xarray/tests/test_backends.py
@@ -1137,8 +1137,10 @@ class NetCDF4DataTest(BaseNetCDF4Test, TestCase):
         # should be fixed in netcdf4 v1.3.1
         with mock.patch('netCDF4.__version__', '1.2.4'):
             with warnings.catch_warnings():
-                warnings.simplefilter("error")
-                with raises_regex(Warning, 'segmentation fault'):
+                message = ('A segmentation fault may occur when the '
+                           'file path has exactly 88 characters')
+                warnings.filterwarnings('error', message)
+                with pytest.raises(Warning):
                     # Need to construct 88 character filepath
                     xr.Dataset().to_netcdf('a' * (88 - len(os.getcwd()) - 1))