Repository: getsentry/responses

Issue:
CustomRegistry - improve reset() availability
Hi all,

Thanks again for the CustomRegistry-implementation! It makes it for us at Moto much easier to have fine-grained control over the matching order/priority.

One painpoint I ran into, when converting everything to work with 0.1.7.0, was the `reset`-api. We have a global `RequestMock`-object that does need to be reset occasionally, but we want to keep the custom registry and the passthru's.

Our current implementation looks like this:
```
responses_mock.reset()
responses_mock._set_registry(CustomRegistry)
responses_mock.add_passthru("http")
```

There's two downsides to this: 
 - We're accessing the internal API
 - We're duplicating the configuration on creation and reset

### Some solutions that I've come up with:
1) Extend the reset-API to configure what needs to be reset, keeping the current implementation as default
```
def reset(keep_passthru=False, keep_registry=False):
    ...
```

2) Make the `set_registry(..)` API public

3) Make the `get_registry()` API public. This would allow us to call the `reset`-API of the registry directly:
```
def within_our_logic:
    responses_mock.get_registry().reset()
```

Anyone of these solutions would simplify our implementation, and make it less brittle, and would therefore be very welcome.
(All three of them would be even better of course, to have some flexibility!)

Any thoughts on whether these solutions are acceptable? I'd be happy to create a PR for them, just wanted to get some feedback first whether this would work for you.

Discussion:
markstory: Looks good but there are some conflicts that need to be fixed up.

Patch:
diff --git a/CHANGES b/CHANGES
index 2c926ba..66c1659 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,7 @@
 0.19.0
 ------
 
+* Expose `get_registry()` method of `RequestsMock` object. Replaces internal `_get_registry()`.
 * Added support for `async/await` functions.
 
 0.18.0
diff --git a/README.rst b/README.rst
index d376768..eb89879 100644
--- a/README.rst
+++ b/README.rst
@@ -482,20 +482,26 @@ Example that shows how to set custom registry
         pass
 
 
+    print("Before tests:", responses.mock.get_registry())
     """ Before tests: <responses.registries.FirstMatchRegistry object> """
 
     # using function decorator
     @responses.activate(registry=CustomRegistry)
     def run():
+        print("Within test:", responses.mock.get_registry())
         """ Within test: <__main__.CustomRegistry object> """
 
     run()
+
+    print("After test:", responses.mock.get_registry())
     """ After test: <responses.registries.FirstMatchRegistry object> """
 
     # using context manager
     with responses.RequestsMock(registry=CustomRegistry) as rsps:
+        print("In context manager:", rsps.get_registry())
         """ In context manager: <__main__.CustomRegistry object> """
 
+    print("After exit from context manager:", responses.mock.get_registry())
     """
     After exit from context manager: <responses.registries.FirstMatchRegistry object>
     """
diff --git a/responses/__init__.py b/responses/__init__.py
index b964bcf..940b742 100644
--- a/responses/__init__.py
+++ b/responses/__init__.py
@@ -504,7 +504,7 @@ class RequestsMock(object):
         self.target = target
         self._patcher = None
 
-    def _get_registry(self):
+    def get_registry(self):
         return self._registry
 
     def _set_registry(self, new_registry):
diff --git a/responses/__init__.pyi b/responses/__init__.pyi
index 183f452..93e432d 100644
--- a/responses/__init__.pyi
+++ b/responses/__init__.pyi
@@ -200,7 +200,7 @@ class RequestsMock:
     def assert_call_count(self, url: str, count: int) -> bool: ...
     def registered(self) -> List[Any]: ...
     def _set_registry(self, registry: Any) -> None: ...
-    def _get_registry(self) -> Any: ...
+    def get_registry(self) -> Any: ...
 
 
 HeaderSet = Optional[Union[Mapping[str, str], List[Tuple[str, str]]]]


Test patch:
diff --git a/responses/test_registries.py b/responses/test_registries.py
index b4dd8cc..145bc02 100644
--- a/responses/test_registries.py
+++ b/responses/test_registries.py
@@ -28,12 +28,12 @@ def test_set_registry():
 
     @responses.activate(registry=CustomRegistry)
     def run_with_registry():
-        assert type(responses.mock._get_registry()) == CustomRegistry
+        assert type(responses.mock.get_registry()) == CustomRegistry
 
     @responses.activate
     def run():
         # test that registry does not leak to another test
-        assert type(responses.mock._get_registry()) == registries.FirstMatchRegistry
+        assert type(responses.mock.get_registry()) == registries.FirstMatchRegistry
 
     run_with_registry()
     run()
@@ -48,8 +48,8 @@ def test_set_registry_context_manager():
         with responses.RequestsMock(
             assert_all_requests_are_fired=False, registry=CustomRegistry
         ) as rsps:
-            assert type(rsps._get_registry()) == CustomRegistry
-            assert type(responses.mock._get_registry()) == registries.FirstMatchRegistry
+            assert type(rsps.get_registry()) == CustomRegistry
+            assert type(responses.mock.get_registry()) == registries.FirstMatchRegistry
 
     run()
     assert_reset()
@@ -63,7 +63,7 @@ def test_registry_reset():
         with responses.RequestsMock(
             assert_all_requests_are_fired=False, registry=CustomRegistry
         ) as rsps:
-            rsps._get_registry().reset()
+            rsps.get_registry().reset()
             assert not rsps.registered()
 
     run()