code: def test_librarymode(path=None):
      Dataset(path).create()
      was_mode = datalad.__runtime_mode
      try:
          # clean --dry-run is just a no-op command that is cheap
          # to execute. It has no particular role here, other than
          # to make the code pass the location where library mode
          # should be turned on via the cmdline API
          run_main(
              [
                  "-c",
                  "datalad.runtime.librarymode=yes",
                  "clean",
                  "-d",
                  path,
                  "--dry-run",
              ]
          )
          ok_(datalad.in_librarymode())
      finally:
          # restore pre-test behavior
          datalad.__runtime_mode = was_mode
          datalad.cfg.overrides.pop("datalad.runtime.librarymode")
  
imports: import os
  import re
  from io import StringIO
  from unittest.mock import patch
  import pytest
  import datalad
  from datalad import __version__
  from datalad.api import Dataset, create
  from datalad.cmd import StdOutErrCapture
  from datalad.cmd import WitlessRunner
  from datalad.interface.base import get_interface_groups
  from datalad.tests.utils_pytest import SkipTest, assert_equal, assert_in, assert_not_in, assert_raises, assert_re_in, eq_, in_, ok_, ok_startswith, on_windows, skip_if_no_module, slow, with_tempfile
  from datalad.ui.utils import get_console_width, get_terminal_size
  from datalad.utils import chpwd
  from ..helpers import get_commands_from_groups
  from ..main import main
label_desc: Use image node_id 16 for calling a global function with example usage: test_librarymode(path) without return types