Test utils and imporved local_stack context manager