code: def test_lock_if_check_fails(tempfile=None):
      # basic test, should never try to lock so filename is not important
      with lock_if_check_fails(True, None) as (check, lock):
          assert check is True
          assert lock is None
      assert check  # still available outside
      # and with a callable
      with lock_if_check_fails(lambda: "valuable", None) as (
          check,
          lock,
      ):
          eq_(check, "valuable")
          assert lock is None
      eq_(check, "valuable")
  
      # basic test, should never try to lock so filename is not important
      with lock_if_check_fails(False, tempfile) as (check, lock):
          ok_(lock)
          ok_exists(tempfile + ".lck")
      assert not op.exists(
          tempfile + ".lck"
      )  # and it gets removed after
  
      # the same with providing operation
      # basic test, should never try to lock so filename is not important
      with lock_if_check_fails(False, tempfile, operation="get") as (
          check,
          lock,
      ):
          ok_(lock)
          ok_exists(tempfile + ".get-lck")
      assert not op.exists(
          tempfile + ".get-lck"
      )  # and it gets removed after
  
      from multiprocessing import (
          Process,
          Queue,
      )
  
      q = Queue()
      p = Process(target=Subproc(tempfile), args=(q,))
  
      # now we need somehow to actually check the bloody lock functioning
      with lock_if_check_fails(
          (op.exists, (tempfile,)), tempfile, _return_acquired=True
      ) as (check, lock, acquired):
          eq_(check, False)
          ok_(lock)
          ok_(acquired)
          # but now we will try to lock again, but we need to do it in another
          # process
          p.start()
          assert q.get() is False
          p.join()
          with open(tempfile, "w") as f:
              pass
          ok_exists(tempfile)
      ok_exists(tempfile)
  
      # and we redo -- it will acquire it
      p = Process(target=Subproc(tempfile), args=(q,))
      p.start()
      ok_(q.get())
      p.join()
  
file_path: datalad/datalad/support/tests/test_locking.py
imports: import os
  import os.path
  import sys
  from pathlib import Path
  from time import time
  from fasteners import InterProcessLock
  from datalad.tests.utils_pytest import assert_false, assert_greater, assert_in, assert_not_in, assert_raises, assert_true, eq_, ok_, ok_exists, on_osx, with_tempfile
  from ...cmd import CommandError, StdOutErrCapture, WitlessRunner
  from ...utils import ensure_unicode
  from ..locking import lock_if_check_fails, try_lock_informatively
label_desc: Use image node_id 1 for calling a global function with example usage: test_lock_if_check_fails(tempfile) without return types