[1.7.x] Fixed formtools tests with Python 2

Fixes #19905 again.
Backport of 1aaf4053f5 from master.