Conditionally enter a context manager