Add sphinx test

Adds a test that the Sphinx build succeeds (0 exit status) and has no warnings or errors in the stdout or stderr.

1575808 has been cherry-picked into this branch from another PR so that the new test passes.
It's actually like that because it's trying to remove at most one matching warning for each allowed warning. Trying to prevent people from adding new instances of the allowed warnings to the build (but still allow the allowed warnings to change lines).

It wasn't actually achieving that aim but I've tweaked it now so that it does