[1.6.x] Fixed 9244447c -- incomplete backport.

The test client had been refactored in the mean time. This commit
de-factors the fix. Refs #20530.
[1.6.x] Fixed deprecation warning on Python 3

Backport of b7451b72 from master.