diff --git a/tests/integration/test_requests.py b/tests/integration/test_requests.py index dbde0d48..0ce3a66d 100644 --- a/tests/integration/test_requests.py +++ b/tests/integration/test_requests.py @@ -310,3 +310,13 @@ def test_post_unicode_match_on_body(tmpdir, httpbin_both): req2 = requests.post(url, data).content assert req1 == req2 + + +def test_duplicate_get_allow_playback_repeats(tmpdir, httpbin_both): + """Ensure that duplicate requests are not included in the cassette on record.""" + with vcr.use_cassette(str(tmpdir.join("allow_repeats.yaml")), allow_playback_repeats=True) as cass: + requests.get(httpbin_both + "/same") + requests.get(httpbin_both + "/different") + requests.get(httpbin_both + "/same") + + assert len(cass) == 2 diff --git a/vcr/cassette.py b/vcr/cassette.py index 5a189e32..f38994e4 100644 --- a/vcr/cassette.py +++ b/vcr/cassette.py @@ -247,7 +247,12 @@ def _responses(self, request): def can_play_response_for(self, request): request = self._before_record_request(request) - return request and request in self and self.record_mode != RecordMode.ALL and self.rewound + return ( + request + and request in self + and self.record_mode != RecordMode.ALL + and (self.rewound or self.allow_playback_repeats) + ) def play_response(self, request): """