SageMath makes some matplotlib plots as part of its tests but these fail if DISPLAY is unset. This is the case on different autobuilders. The failures can be avoided by adding matplotlib.use('Agg') in the early parts of the tests, as suggested by this stackoverflow post but I wonder if matplotlib should be doing this itself automatically. It would certainly be a neater solution than to patch SageMath.
See here for the corresponding ticket on their trac.