Fix variable scope in test