Don't execute query if test mode is enabled.

Fixes 16756
Merge pull request #17037 from rallytime/bp-16932

Backport #16932 to 2014.7