Fixed test failures on 1.8.7 caused by 74e59ea

This fixes the backport PR #9899 causing test failures on 1.8.7.