Backport of 7d1e23775344cc3dead03bd4af45f4fdf134b819 from master
This is preparation for landing the template-based widget rendering patch and goes a long way to making these tests more useful for future development. The old doctest heritage is strong here.