"No GDAL environment" appearing in test cases, randomly
In my wrapper library that uses GeoPandas and Fiona, I have test cases that sometimes (!) raises fiona.errors.EnvError: No GDAL environment exists.
The exception happens on gpd.read_file, but before that I open a dozen or two of gpkg files with fiona.
When I make it run in the reverse manner (first, test with gpd.read_file, then many open/close of fiona), it works normally.
Here's my project (to test, clone and do pytest in its root, or ./testdb.sh or ./testcov.sh). For me, all three recently worked ok (Python 3.8.10, Fiona 1.8.17, GeoPandas 0.9.0), although I have no idea how it got fixed (maybe after I started closing one fiona reader manually).
In Github Workflows, it fails. Fail log here.
Looking into tests code, I see there are some tests where I use mask, and these fiona.ogrext.Iterator objects are never closed.
Any suggestions what can be done to make it not fail?
If necessary, I can explain what my code does.
> df = gpd.read_file(d + 'polygons.gpkg')
tests/io/test_io_base.py:14:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.local/lib/python3.8/site-packages/geopandas/io/file.py:203: in _read_file
return GeoDataFrame.from_features(
../../.local/lib/python3.8/site-packages/fiona/env.py:256: in __exit__
delenv()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def delenv():
"""Delete options in the existing environment."""
if not local._env:
> raise EnvError("No GDAL environment exists")
E fiona.errors.EnvError: No GDAL environment exists
../../.local/lib/python3.8/site-packages/fiona/env.py:315: EnvError