I'm running GDAL 2.2.0 and have set up some unit tests to run using Jenkins CI (1.609.2). One of the tests fails every time, even though if I log on to the Jenkins box and run the test manually, everything runs ok.

Here's a simplified version of the code I'm testing (it's a raster checker QA tool):

def check_band_info(ds, expected_max_value=None):
for rc in xrange(1, ds.RasterCount + 1):
    rb = ds.GetRasterBand(rc)

    # more tests here

    if expected_max_value is not None:
        actual_max_value = rb.GetMaximum()
        if actual_max_value is None or actual_max_value > float(expected_max_value):
            print('Band {} Maximum value {}'.format(rc, actual_max_value))

Running gdalinfo on the raster shows band 5 does have a maximum value:

Band 5 Block=20x19 Type=Int32, ColorInterp=Undefined
Min=140.000 Max=654.000
Minimum=140.000, Maximum=654.000, Mean=378.645, StdDev=103.930
NoData Value=-2147483648

However, the test fails with:

FAIL: test_max_value_pass (autoqc.test.test_raster_checker.Test)
Traceback (most recent call last):
  File "/home/user/.jenkins/workspace/autoqc/test/test_raster_checker.py", line 120, in test_max_value_pass
  File "/home/user/.jenkins/workspace/autoqc/test/test_raster_checker.py", line 33, in _test_task
    self.assertEqual(result[-1][-1], message)
AssertionError: "Actual ['Band 5 Maximum value None']" != 'OK'


I've added a skip to get the build to pass, but I shouldn't need to as on every other machine, and when I run it manually this test passes.

Has anyone seen something similar? Is there a race condition that is making gdal return None, but only when running under CI?

  • 1
    We are not creating the raster in code - it's a tiff file that was created a few years ago. I've had another look at it though and can see the problem occurs when stats have not been calculated on the raster band, so thanks for the bump!
    – jon_two
    Commented Mar 13, 2023 at 11:36

1 Answer 1


You can try out following lines in your code:

band = dataset.GetRasterBand(1)
min = band.GetMinimum()
max = band.GetMaximum()
if not min or not max:
    (min,max) = band.ComputeRasterMinMax(True)
  • Is this mainly for rasters where statistics have not yet been calculated? This raster definitely has stats, as the gdalinfo output shows.
    – jon_two
    Commented Nov 6, 2017 at 16:29
  • No. In my case I solved this kind of problem with these instructions.
    – xunilk
    Commented Nov 6, 2017 at 16:40
  • 1
    Accepting as I've had another look and computing stats on the raster band makes the test work. The reason it usually passed on other machines is that stats had been calculated for that tiff and there was a .aux.xml file with it. When running on CI, there was no .aux.xml file so the test failed.
    – jon_two
    Commented Mar 13, 2023 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.