code: def test_from_env_overrides():
      cfg = ConfigManager()
      assert_not_in("datalad.FoO", cfg)
  
      # Some details, like case and underscores, cannot be handled by the direct
      # environment variable mapping.
      with patch.dict("os.environ", {"DATALAD_FOO": "val"}):
          cfg.reload()
          assert_not_in("datalad.FoO", cfg)
          assert_equal(cfg["datalad.foo"], "val")
  
      # But they can be handled via DATALAD_CONFIG_OVERRIDES_JSON.
      with patch.dict(
          "os.environ",
          {"DATALAD_CONFIG_OVERRIDES_JSON": '{"datalad.FoO": "val"}'},
      ):
          cfg.reload()
          assert_equal(cfg["datalad.FoO"], "val")
  
      # DATALAD_CONFIG_OVERRIDES_JSON isn't limited to datalad variables.
      with patch.dict(
          "os.environ",
          {"DATALAD_CONFIG_OVERRIDES_JSON": '{"a.b.c": "val"}'},
      ):
          cfg.reload()
          assert_equal(cfg["a.b.c"], "val")
  
      # Explicitly provided DATALAD_ variables take precedence over those in
      # DATALAD_CONFIG_OVERRIDES_JSON.
      with patch.dict(
          "os.environ",
          {
              "DATALAD_CONFIG_OVERRIDES_JSON": '{"datalad.foo": "val"}',
              "DATALAD_FOO": "val-direct",
          },
      ):
          cfg.reload()
          assert_equal(cfg["datalad.foo"], "val-direct")
  
      # JSON decode errors don't lead to crash.
      with patch.dict(
          "os.environ", {"DATALAD_CONFIG_OVERRIDES_JSON": "{"}
      ):
          with swallow_logs(logging.WARNING) as cml:
              cfg.reload()
          assert_in("Failed to load DATALAD_CONFIG_OVERRIDE", cml.out)
  
imports: import logging
  import os
  from os.path import exists
  from os.path import join
  from unittest.mock import patch
  import pytest
  from datalad import cfg
  from datalad.api import create
  from datalad.cmd import CommandError
  from datalad.config import ConfigManager, _where_to_scope, parse_gitconfig_dump, rewrite_url, write_config_section
  from datalad.distribution.dataset import Dataset
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.gitrepo import GitRepo
  from datalad.tests.utils_pytest import DEFAULT_BRANCH, DEFAULT_REMOTE, assert_equal, assert_false, assert_in, assert_not_equal, assert_not_in, assert_raises, assert_true, chpwd, ok_file_has_content, with_tempfile, with_testsui, with_tree
  from datalad.utils import Path, get_home_envvars, swallow_logs
label_desc: Use image node_id 7 for calling a global function with example usage: test_from_env_overrides() without return types