openeo-python-client icon indicating copy to clipboard operation
openeo-python-client copied to clipboard

urllib request mocking for pystac/load_stac related tests?

Open soxofaan opened this issue 11 months ago • 3 comments

The openEO python client uses the popular requests module for HTTP requests. Testing of that is currently done with the requests_mock module.

For STAC support (e.g. load_stac) we are depending more and more on pystac which uses urllib/urllib3 internally. This is obviously not covered by requests_mock so we need something else as urllib mock utility. I might have missed something obvious but didn't find anything up to date yet

Because of lack of real URL mocking for urrlib, we currently workaround that with local paths to temp files, which is accepted by pystac. e.g.: https://github.com/Open-EO/openeo-python-client/blob/026881df787de007205e110f765260aeaf2e9876/tests/rest/test_connection.py#L2950-L2957

That works for simple use cases, but it hinders testings of real HTTP functionality (e.g. handling of failed requests, handling relative URLs, ...)

soxofaan avatar Feb 24 '25 11:02 soxofaan

There's openeo_driver.testing.UrllibMocker and tests.conftest.UrllibPoolManagerMocker in openeo-geopyspark-driver.

bossie avatar Feb 24 '25 12:02 bossie

indeed, but instead of these somewhat brittle DIY hacks I'm hoping to find some some 3rd party solution that is more standard/official/feature-rich

soxofaan avatar Feb 25 '25 08:02 soxofaan

Yeah, they have shortcomings as well.

bossie avatar Feb 25 '25 09:02 bossie