def test_loaders_raise_on_syntax_error(file_factory, filename, silent):
    """When dynaconf tries to load a file with syntax error, an error is raised."""
    # invalid syntax for any file format
    filepath = file_factory(filename, "asdf")

    # assert on initialization
    with pytest.raises(Exception):
        settings = Dynaconf(settings_files=filepath, silent=silent)
        settings.as_dict()

    # assert on explicit load call
    settings = Dynaconf()
    with pytest.raises(Exception):
        settings.load_file(path=filepath, silent=silent)
When dynaconf tries to load a file with syntax error, an error is raised.
tests/test_loaders.py