1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00
Terseus f48922ce09 Fix not calling all the exit stack when record_on_exception is False
The initial technique to implement `record_on_exception=False` was to
not emptying the generator returned by
`CassetteContextDecorator._patch_generator` when an exception happens to
skip the `cassette._save` call, however this had the side effect of not
emptying the `ExitStack` created inside the generator which contains the
`_patch.__exit__` calls to remove the patches.

This was innocuous in CPython, which uses a reference counting garbage
collector so the `ExitStack` was immediately collected after losing
scope and therefore its `__exit__` method executed.
Pypy, on the other hand, uses a generational garbage collector so its
objects may survive more time, enough for the `ExitStack` not called
until much later, which may cause the patches to live more than expected
when `record_on_exception=False`.

This was found because the test
`test_nesting_context_managers_by_checking_references_of_http_connection`
was failing because it was executed after
`test_dont_record_on_exception`.

Now the cassette instance is saved inside the `CassetteContextDecorator`
instance to have better control on where to save the cassette, and moved
the `cassette._save` call from the `_patch_generator` method to the
`__exit__` method to be free to empty the generator and remove the
patches always.
2022-10-31 22:43:03 -03:00
2022-10-31 22:18:30 -03:00
2022-08-31 14:14:32 -05:00
2022-10-31 22:43:03 -03:00
2015-03-31 13:02:59 -07:00
2022-10-09 11:35:37 -03:00
2021-11-02 14:57:19 -10:00
2020-10-05 09:45:55 -05:00
2015-06-30 12:19:05 +01:00
2022-10-31 09:00:35 -03:00
2022-10-31 09:00:35 -03:00

###########
VCR.py 📼
###########


|PyPI| |Python versions| |Build Status| |CodeCov| |Gitter| |CodeStyleBlack|

----

.. image:: https://vcrpy.readthedocs.io/en/latest/_images/vcr.svg
   :alt: vcr.py logo


This is a Python version of `Ruby's VCR
library <https://github.com/vcr/vcr>`__.

Source code
  https://github.com/kevin1024/vcrpy

Documentation
  https://vcrpy.readthedocs.io/

Rationale
---------

VCR.py simplifies and speeds up tests that make HTTP requests. The
first time you run code that is inside a VCR.py context manager or
decorated function, VCR.py records all HTTP interactions that take
place through the libraries it supports and serializes and writes them
to a flat file (in yaml format by default). This flat file is called a
cassette. When the relevant piece of code is executed again, VCR.py
will read the serialized requests and responses from the
aforementioned cassette file, and intercept any HTTP requests that it
recognizes from the original test run and return the responses that
corresponded to those requests. This means that the requests will not
actually result in HTTP traffic, which confers several benefits
including:

-  The ability to work offline
-  Completely deterministic tests
-  Increased test execution speed

If the server you are testing against ever changes its API, all you need
to do is delete your existing cassette files, and run your tests again.
VCR.py will detect the absence of a cassette file and once again record
all HTTP interactions, which will update them to correspond to the new
API.

Usage with Pytest
-----------------

There is a library to provide some pytest fixtures called pytest-recording https://github.com/kiwicom/pytest-recording

License
-------

This library uses the MIT license. See `LICENSE.txt <LICENSE.txt>`__ for
more details

.. |PyPI| image:: https://img.shields.io/pypi/v/vcrpy.svg
   :target: https://pypi.python.org/pypi/vcrpy
.. |Python versions| image:: https://img.shields.io/pypi/pyversions/vcrpy.svg
   :target: https://pypi.python.org/pypi/vcrpy
.. |Build Status| image:: https://github.com/kevin1024/vcrpy/actions/workflows/main.yml/badge.svg
   :target: https://github.com/kevin1024/vcrpy/actions
.. |Gitter| image:: https://badges.gitter.im/Join%20Chat.svg
   :alt: Join the chat at https://gitter.im/kevin1024/vcrpy
   :target: https://gitter.im/kevin1024/vcrpy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
.. |CodeCov| image:: https://codecov.io/gh/kevin1024/vcrpy/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/kevin1024/vcrpy
   :alt: Code Coverage Status
.. |CodeStyleBlack| image:: https://img.shields.io/badge/code%20style-black-000000.svg 
   :target: https://github.com/psf/black
   :alt: Code Style: black
Description
Automatically mock your HTTP interactions to simplify and speed up testing
Readme 6.3 MiB
Languages
Python 99.9%