Factor out the discover logic to the test module

This avoids duplication in sugar and sugar-toolkit-gtk3
makefiles.
Move setting AT_SPI_CLIENT to discover

It needs to be called as early as possible before unit tests
has a chance to import gtk.

Hopefully will fix random test failures we are seeing in buildbot.