Take alternative workdir into account in test.
Redmine #2573; correct mistake in placement of pragmas

The #pragma is not allowed inside functions, so move it outside.
Merge pull request #668 from cduclos/3.5.x

Cherry picking two changes to make 3.5 work again.