def test_inspect_to_file(tmp_path):
    """Assert file is written correctly with 'to_file' option"""
    os.environ["DYNACONF_FOO"] = "from_environ"
    os.environ["DYNACONF_BAR"] = "environ_only"
    filename = create_file(tmp_path / "a.yaml", "foo: from_yaml")
    settings = Dynaconf(settings_file=filename)

    file_out = tmp_path / "output.yml"
    inspect_settings(settings, dumper="yaml", to_file=file_out)

    # open created file
    assert file_out.read_text() == dedent(
        f"""\
        header:
          env_filter: None
          key_filter: None
          new_first: 'True'
          history_limit: None
          include_internal: 'False'
        current:
          FOO: from_environ
          BAR: environ_only
        history:
        - loader: env_global
          identifier: DYNACONF
          env: global
          merged: false
          value:
            FOO: from_environ
            BAR: environ_only
        - loader: yaml
          identifier: {filename}
          env: default
          merged: false
          value:
            FOO: from_yaml
        - loader: set_method
          identifier: settings_module_method
          env: global
          merged: false
          value:
            SETTINGS_MODULE: {filename}
        - loader: set_method
          identifier: init_kwargs
          env: global
          merged: false
          value:
            SETTINGS_FILE_FOR_DYNACONF: {filename}
          """
    )
Assert file is written correctly with 'to_file' option
tests/test_inspect.py