Repository: great-expectations/great_expectations

Issue:
Use cleaner solution for non-truncating division in python 2
Prefer `from __future__ import division` to `1.*x/y`


Discussion:
Done inline during improve_partitions push.

Resolving patch:
diff --git a/great_expectations/data_context/data_context/abstract_data_context.py b/great_expectations/data_context/data_context/abstract_data_context.py
--- a/great_expectations/data_context/data_context/abstract_data_context.py
+++ b/great_expectations/data_context/data_context/abstract_data_context.py
@@ -642,6 +642,7 @@ def delete_datasource(
         if save_changes:
             self._datasource_store.delete_by_name(datasource_name)
         self._cached_datasources.pop(datasource_name, None)
+        self.config.datasources.pop(datasource_name, None)
 
     def store_evaluation_parameters(
         self, validation_results, target_store_name=None


Test patch:
diff --git a/tests/data_context/abstract_data_context/__init__.py b/tests/data_context/abstract_data_context/__init__.py
new file mode 100644
diff --git a/tests/data_context/abstract_data_context/test_datasource_delete.py b/tests/data_context/abstract_data_context/test_datasource_delete.py
new file mode 100644
--- /dev/null
+++ b/tests/data_context/abstract_data_context/test_datasource_delete.py
@@ -0,0 +1,60 @@
+import pytest
+
+from great_expectations import DataContext
+from great_expectations.data_context import CloudDataContext
+from great_expectations.data_context.types.base import DatasourceConfig
+
+
+def test_datasource_delete_removes_from_cache_and_config_data_context(
+    empty_data_context: DataContext, datasource_config: DatasourceConfig
+):
+    """context.datasource_delete should remove from the datasource cache and also config independent of the save_changes setting."""
+
+    context: DataContext = empty_data_context
+    datasource_name: str = "my_datasource"
+
+    assert len(context.datasources) == 0
+    datasource_config["name"] = datasource_name
+    context.add_datasource(**datasource_config.to_dict())
+
+    # ensure datasource is accessible
+    assert len(context.datasources) == 1
+    assert datasource_name in context.datasources
+    assert datasource_name in context.config.datasources
+    assert context._datasource_store.retrieve_by_name(datasource_name=datasource_name)
+
+    context.delete_datasource(datasource_name)
+
+    # ensure deleted
+    assert len(context.datasources) == 0
+    assert datasource_name not in context.datasources
+    assert datasource_name not in context.config.datasources
+    with pytest.raises(ValueError):
+        assert not context._datasource_store.retrieve_by_name(
+            datasource_name=datasource_name
+        )
+
+
+def test_datasource_delete_removes_from_cache_and_config_cloud_data_context(
+    empty_cloud_data_context: CloudDataContext, datasource_config: DatasourceConfig
+):
+    """context.datasource_delete should remove from the datasource cache and also config independent of the save_changes setting."""
+
+    context: DataContext = empty_cloud_data_context
+    datasource_name: str = "my_datasource"
+
+    assert len(context.datasources) == 0
+    datasource_config["name"] = datasource_name
+    context.add_datasource(**datasource_config.to_dict())
+
+    # ensure datasource is accessible
+    assert len(context.datasources) == 1
+    assert datasource_name in context.datasources
+    assert datasource_name in context.config.datasources
+
+    context.delete_datasource(datasource_name)
+
+    # ensure deleted
+    assert len(context.datasources) == 0
+    assert datasource_name not in context.datasources
+    assert datasource_name not in context.config.datasources