code: def test_use_repl_context_if_available(tmp_path, monkeypatch):
      # Simulate a case where `dbruntime.databricks_repl_context.get_context` is unavailable.
      with pytest.raises(
          ModuleNotFoundError, match="No module named 'dbruntime'"
      ):
          from dbruntime.databricks_repl_context import (
              get_context,
          )  # noqa: F401
  
      command_context_mock = mock.MagicMock()
      command_context_mock.jobId().get.return_value = "job_id"
      command_context_mock.tags().get(  # pylint: disable=not-callable
          "jobType"
      ).get.return_value = "NORMAL"
      with mock.patch(
          "mlflow.utils.databricks_utils._get_command_context",
          return_value=command_context_mock,
      ) as mock_get_command_context:
          assert databricks_utils.get_job_id() == "job_id"
          mock_get_command_context.assert_called_once()
  
      # Create a fake databricks_repl_context module
      dbruntime = tmp_path.joinpath("dbruntime")
      dbruntime.mkdir()
      dbruntime.joinpath("databricks_repl_context.py").write_text(
          """
  def get_context():
      pass
  """
      )
      monkeypatch.syspath_prepend(str(tmp_path))
  
      # Simulate a case where the REPL context object is not initialized.
      with mock.patch(
          "dbruntime.databricks_repl_context.get_context",
          return_value=None,
      ) as mock_get_context, mock.patch(
          "mlflow.utils.databricks_utils._get_command_context",
          return_value=command_context_mock,
      ) as mock_get_command_context:
          assert databricks_utils.get_job_id() == "job_id"
          assert mock_get_command_context.call_count == 1
  
      with mock.patch(
          "dbruntime.databricks_repl_context.get_context",
          return_value=mock.MagicMock(jobId="job_id"),
      ) as mock_get_context, mock.patch(
          "mlflow.utils.databricks_utils._get_dbutils"
      ) as mock_dbutils:
          assert databricks_utils.get_job_id() == "job_id"
          mock_get_context.assert_called_once()
          mock_dbutils.assert_not_called()
  
      with mock.patch(
          "dbruntime.databricks_repl_context.get_context",
          return_value=mock.MagicMock(
              notebookId="notebook_id",
              notebookPath="/Repos/notebook_path",
          ),
      ) as mock_get_context, mock.patch(
          "mlflow.utils.databricks_utils._get_property_from_spark_context"
      ) as mock_spark_context:
          assert databricks_utils.get_notebook_id() == "notebook_id"
          assert databricks_utils.is_in_databricks_repo_notebook()
          assert mock_get_context.call_count == 2
          mock_spark_context.assert_not_called()
  
      with mock.patch(
          "dbruntime.databricks_repl_context.get_context",
          return_value=mock.MagicMock(
              notebookId="notebook_id",
              notebookPath="/Users/notebook_path",
          ),
      ) as mock_get_context, mock.patch(
          "mlflow.utils.databricks_utils._get_property_from_spark_context"
      ) as mock_spark_context:
          assert not databricks_utils.is_in_databricks_repo_notebook()
  
      with mock.patch(
          "dbruntime.databricks_repl_context.get_context",
          return_value=mock.MagicMock(isInCluster=True),
      ) as mock_get_context, mock.patch(
          "mlflow.utils._spark_utils._get_active_spark_session"
      ) as mock_spark_session:
          assert databricks_utils.is_in_cluster()
          mock_get_context.assert_called_once()
          mock_spark_session.assert_not_called()
  
imports: import builtins
  import sys
  from unittest import mock
  import pytest
  from databricks_cli.configure.provider import DatabricksConfig
  from mlflow.exceptions import MlflowException
  from mlflow.utils import databricks_utils
  from mlflow.utils.databricks_utils import check_databricks_secret_scope_access, get_mlflow_credential_context_by_run_id, get_workspace_info_from_databricks_secrets, get_workspace_info_from_dbutils, is_databricks_default_tracking_uri, is_running_in_ipython_environment
  from mlflow.utils.uri import construct_db_uri_from_profile
  from tests.helper_functions import mock_method_chain
label_desc: Use image node_id 18 for calling a global function with example usage: test_use_repl_context_if_available(tmp_path, monkeypatch) without return types