Repository: getsentry/responses
Pull request #518 (2022-03-17 17:07:41)

minor doc clean up

codecov[bot]: # [Codecov](https://app.codecov.io/gh/getsentry/responses/compare/518?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) Report
> Merging [#518](https://app.codecov.io/gh/getsentry/responses/compare/518?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) (0d27edc) into [master](https://codecov.io/gh/getsentry/responses/commit/1724937f354bb1ebe5d4dc4d6b976a175396b0ac?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) (1724937) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@            Coverage Diff            @@
##            master      #518   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines         2305      2305           
=========================================
  Hits          2305      2305           
```



------

[Continue to review full report at Codecov](https://app.codecov.io/gh/getsentry/responses/compare/518?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://app.codecov.io/gh/getsentry/responses/compare/518?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry). Last update [1724937...0d27edc](https://app.codecov.io/gh/getsentry/responses/compare/518?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry).


Patch:
diff --git a/CHANGES b/CHANGES
index 6e1bcf1..cd8cc23 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,7 @@
   since they are not actual properties of the class instance.
   Use `responses.mock.assert_all_requests_are_fired`,
   `responses.mock.passthru_prefixes`, `responses.mock.target` instead.
+* Fixed the issue when `reset()` method was called in not stopped mock. See #511
 
 0.19.0
 ------
diff --git a/README.rst b/README.rst
index 5d23906..cd04df3 100644
--- a/README.rst
+++ b/README.rst
@@ -32,6 +32,38 @@ Installing
 ``pip install responses``
 
 
+Deprecations and Migration Path
+-------------------------------
+
+Here you will find a list of deprecated functionality and a migration path for each.
+Please ensure to update your code according to the guidance.
+
+.. list-table:: Deprecation and Migration
+   :widths: 50 25 50
+   :header-rows: 1
+
+   * - Deprecated Functionality
+     - Deprecated in Version
+     - Migration Path
+   * - ``responses.json_params_matcher``
+     - 0.14.0
+     - ``responses.matchers.json_params_matcher``
+   * - ``responses.urlencoded_params_matcher``
+     - 0.14.0
+     - ``responses.matchers.urlencoded_params_matcher``
+   * - ``stream`` argument in ``Response`` and ``CallbackResponse``
+     - 0.15.0
+     - Use ``stream`` argument in request directly.
+   * - ``match_querystring`` argument in ``Response`` and ``CallbackResponse``.
+     - 0.17.0
+     - Use ``responses.matchers.query_param_matcher`` or ``responses.matchers.query_string_matcher``
+   * - ``responses.assert_all_requests_are_fired``, ``responses.passthru_prefixes``, ``responses.target``
+     - 0.20.0
+     - Use ``responses.mock.assert_all_requests_are_fired``,
+       ``responses.mock.passthru_prefixes``, ``responses.mock.target`` instead.
+
+
+
 Basics
 ------
 
@@ -107,7 +139,7 @@ The following attributes can be passed to a Response mock:
 method (``str``)
     The HTTP method (GET, POST, etc).
 
-url (``str`` or compiled regular expression)
+url (``str`` or ``compiled regular expression``)
     The full resource URL.
 
 match_querystring (``bool``)
@@ -140,8 +172,9 @@ stream (``bool``)
 auto_calculate_content_length (``bool``)
     Disabled by default. Automatically calculates the length of a supplied string or JSON body.
 
-match (``list``)
-    A list of callbacks to match requests based on request attributes.
+match (``tuple``)
+    An iterable (``tuple`` is recommended) of callbacks to match requests
+    based on request attributes.
     Current module provides multiple matchers that you can use to match:
 
     * body contents in JSON format
@@ -785,8 +818,8 @@ the ``assert_all_requests_are_fired`` value:
                      body='{}', status=200,
                      content_type='application/json')
 
-assert_call_count
------------------
+Assert Request Call Count
+-------------------------
 
 Assert that the request was called exactly n times.
 
@@ -834,13 +867,13 @@ You can also add multiple responses for the same url:
 Using a callback to modify the response
 ---------------------------------------
 
-If you use customized processing in `requests` via subclassing/mixins, or if you
-have library tools that interact with `requests` at a low level, you may need
+If you use customized processing in ``requests`` via subclassing/mixins, or if you
+have library tools that interact with ``requests`` at a low level, you may need
 to add extended processing to the mocked Response object to fully simulate the
-environment for your tests.  A `response_callback` can be used, which will be
+environment for your tests.  A ``response_callback`` can be used, which will be
 wrapped by the library before being returned to the caller.  The callback
-accepts a `response` as it's single argument, and is expected to return a
-single `response` object.
+accepts a ``response`` as it's single argument, and is expected to return a
+single ``response`` object.
 
 ..  code-block:: python
 
@@ -884,7 +917,7 @@ need to allow an entire domain or path subtree to send requests:
     responses.add_passthru(re.compile('https://percy.io/\\w+'))
 
 
-Lastly, you can use the `response.passthrough` attribute on `BaseResponse` or
+Lastly, you can use the ``response.passthrough`` attribute on ``BaseResponse`` or
 use ``PassthroughResponse`` to enable a response to behave as a pass through.
 
 .. code-block:: python
diff --git a/responses/__init__.py b/responses/__init__.py
index 91ee3ea..d8d5438 100644
--- a/responses/__init__.py
+++ b/responses/__init__.py
@@ -560,7 +560,6 @@ class RequestsMock(object):
         self._registry = FirstMatchRegistry()
         self._calls.reset()
         self.passthru_prefixes = ()
-        self._patcher = None
 
     def add(
         self,
@@ -834,6 +833,8 @@ class RequestsMock(object):
     def start(self):
         if self._patcher:
             # we must not override value of the _patcher if already applied
+            # this prevents issues when one decorated function is called from
+            # another decorated function
             return
 
         def unbound_on_send(adapter, request, *a, **kwargs):
@@ -847,6 +848,10 @@ class RequestsMock(object):
             # prevent stopping unstarted patchers
             self._patcher.stop()
 
+            # once patcher is stopped, clean it. This is required to create a new
+            # fresh patcher on self.start()
+            self._patcher = None
+
         if not self.assert_all_requests_are_fired:
             return
 


Test patch:
diff --git a/responses/tests/test_responses.py b/responses/tests/test_responses.py
index 9f2212c..05e816e 100644
--- a/responses/tests/test_responses.py
+++ b/responses/tests/test_responses.py
@@ -2127,3 +2127,16 @@ class TestShortcuts:
 
         run()
         assert_reset()
+
+
+def test_reset_in_the_middle():
+    @responses.activate
+    def run():
+        with responses.RequestsMock() as rsps2:
+            rsps2.reset()
+        responses.add(responses.GET, "https://example.invalid", status=200)
+        resp = requests.request("GET", "https://example.invalid")
+        assert resp.status_code == 200
+
+    run()
+    assert_reset()