code: def restore_working_directory(tmpdir, request):
      try:
          previous_cwd = os.getcwd()
      except OSError:
          # https://github.com/simonw/datasette/issues/1361
          previous_cwd = None
      tmpdir.chdir()
  
      def return_to_previous():
          os.chdir(previous_cwd)
  
      if previous_cwd is not None:
          request.addfinalizer(return_to_previous)
  
imports: import asyncio
  import httpx
  import os
  import pathlib
  import pytest
  import pytest_asyncio
  import re
  import subprocess
  import tempfile
  import time
  import trustme
label_desc: Use image node_id 7 for calling a global function with example usage: restore_working_directory(tmpdir, request) without return types