def pytest_sessionstart(session: Session) -> None:
    """Create a temporary directory for the BentoML home directory, then monkey patch to config."""
    from bentoml._internal.utils import analytics

    # We need to clear analytics cache before running tests.
    analytics.usage_stats.do_not_track.cache_clear()
    analytics.usage_stats._usage_event_debugging.cache_clear()  # type: ignore (private warning)

    mp = MonkeyPatch()
    config = session.config
    config.add_cleanup(mp.undo)

    _PYTEST_BENTOML_HOME, _PYTEST_MULTIPROC_DIR = _setup_test_directory()

    # The evironment variable patch ensures that we will
    # always build bento using bentoml from source, use the correct
    # test bentoml home directory, and setup prometheus multiproc directory.
    _setup_session_environment(
        mp,
        session,
        ("PROMETHEUS_MULTIPROC_DIR", _PYTEST_MULTIPROC_DIR),
        ("BENTOML_BUNDLE_LOCAL_BUILD", "True"),
        ("__BENTOML_DEBUG_USAGE", "False"),
        ("BENTOML_DO_NOT_TRACK", "True"),
    )

    _setup_session_environment(mp, config, ("BENTOML_HOME", _PYTEST_BENTOML_HOME))
Create a temporary directory for the BentoML home directory, then monkey patch to config.
src/bentoml/testing/pytest/plugin.py