I'm getting intermittent fails with our Python unit tests and I wondered if 
anyone has seen the same issue. I think it's a race condition where a mock 
patch is either not applied at all or maybe applied too slowly so the patched 
function still has its original return value. It might be a pytest issue, but 
I've now seen it with two different GDAL methods so I'm just curious if anyone 
has any idea what may be going on.

The first example I reported on Stack Overflow 
(https://stackoverflow.com/q/75185263/3182496) and looks something like this:

        mock_feat_defn = mocker.patch.object(ogr.FeatureDefn, 'GetFieldCount')
        mock_feat_defn.side_effect = RuntimeError("Some other error message")

        with pytest.raises(RuntimeError, match="Some other error message"):
            get_from_layer_schema(test_lyr, get_names=True, get_types=False)

The second example is this:

        with mock.patch('osgeo.gdal.Driver.Delete', side_effect=None):
            with self.assertRaisesRegex(DatasetError, "Could not delete"):
                delete_path(shp_path)

In both cases we're mocking a GDAL method call to check one of our functions 
correctly raises an error, but sometimes it works and sometimes it doesn't. If 
it's not a GDAL issue, no problem, I will keep looking elsewhere for a solution.

Jon

e: jon.mor...@jbarisk.com
d:+44 (0)1756 587229
t: +44 (0)1756 799919
www.jbarisk.com
All JBA Risk Management's email messages contain confidential information and 
are intended only for the individual(s) named. If you are not the named 
addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by email if you have received this email 
by mistake and delete this email from your system.
JBA Risk Management Limited is registered in England, company number 07732946, 
1 Broughton Park, Old Lane North, Broughton, Skipton, North Yorkshire, BD23 
3FD, England.
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to