diff --git a/xarray/backends/netCDF4_.py b/xarray/backends/netCDF4_.py index 28aa4dbd121..89a0e72ef07 100644 --- a/xarray/backends/netCDF4_.py +++ b/xarray/backends/netCDF4_.py @@ -264,13 +264,13 @@ def open(cls, filename, mode='r', format='NETCDF4', group=None, 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, diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 0bef13a8c43..e0f030368bb 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -1137,8 +1137,10 @@ def test_88_character_filename_segmentation_fault(self): # 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))