[TEST] close REST test execution context only if not null

The context can be null when REST tests are disabled via sysprop.