Michael Foord identified the problem. I am incorrectly interleaving unittest.mock.patch calls which get unwound in the wrong order. On local builds, the tests are run in an order which does not trigger this problem, but I guess fortunately, the buildds run the tests in a different order and the problem becomes evident. Fortunately, it's an easy fix - don't interleave the patch calls.
Michael Foord identified the problem. I am incorrectly interleaving unittest.mock.patch calls which get unwound in the wrong order. On local builds, the tests are run in an order which does not trigger this problem, but I guess fortunately, the buildds run the tests in a different order and the problem becomes evident. Fortunately, it's an easy fix - don't interleave the patch calls.