code: def test(
      implementations,
      valgrind,
      venv_quick=False,
      test_name=None,
      pytest_options=None,
  ):
      """
      Args:
          implementations:
              See top-level option `-i`.
          valgrind:
              See top-level option `--valgrind`.
          venv_quick:
              See top-level option `-v`.
          test_name:
              See top-level option `-t`.
          pytest_options:
              See top-level option `-p`.
      """
      pymupdf_dir_rel = gh_release.relpath(pymupdf_dir)
      if pytest_options is None:
          if valgrind:
              pytest_options = "-s -vv"
          else:
              pytest_options = "-s"
      pytest_arg = pymupdf_dir_rel
      if test_name:
          pytest_arg += f"/{test_name}"
      python = gh_release.relpath(sys.executable)
      log("Running tests with tests/run_compound.py and pytest.")
      try:
          if venv_quick:
              log(
                  f"{venv_quick=}: Not installing test packages: {gh_release.test_packages}"
              )
          else:
              gh_release.run(f"pip install {gh_release.test_packages}")
          implementations_args = (
              f" -i {implementations}" if implementations else ""
          )
          env_extra = None
          if valgrind:
              log("Installing valgrind.")
              gh_release.run(f"sudo apt update")
              gh_release.run(f"sudo apt install valgrind")
              gh_release.run(f"valgrind --version")
  
              log("Running PyMuPDF tests under valgrind.")
              command = (
                  f"{python} {pymupdf_dir_rel}/tests/run_compound.py{implementations_args}"
                  f" valgrind --suppressions={pymupdf_dir_rel}/valgrind.supp --error-exitcode=100 --errors-for-leak-kinds=none --fullpath-after="
                  f" {python} -m pytest {pytest_options} {pytest_arg}"
              )
              env_extra = dict(
                  PYTHONMALLOC="malloc",
                  PYMUPDF_RUNNING_ON_VALGRIND="1",
              )
          elif platform.system() == "OpenBSD":
              # On OpenBSD `pip install pytest` doesn't seem to install the pytest
              # command, so we use `python -m pytest ...`. (This doesn't work on
              # Windows for some reason so we don't use it all the time.)
              command = f"{python} {pymupdf_dir_rel}/tests/run_compound.py{implementations_args} {python} -m pytest {pytest_options} {pytest_arg}"
          else:
              command = f"{python} {pymupdf_dir_rel}/tests/run_compound.py{implementations_args} {python} -m pytest {pytest_options} {pytest_arg}"
  
          log(f"Running tests with tests/run_compound.py and pytest.")
          gh_release.run(command, env_extra=env_extra)
  
      finally:
          log(
              "\n"
              + venv_info(pytest_args=f"{pytest_options} {pytest_arg}")
          )
  
file_path: pymudf/scripts/test.py
imports: import gh_release
  import os
  import platform
  import re
  import subprocess
  import sys
  import textwrap
label_desc: Use image node_id 5 for calling a global function with example usage: test(implementations, valgrind, venv_quick, test_name, pytest_options) without return types