Skip to content

Instantly share code, notes, and snippets.

@selevit
Created July 12, 2021 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selevit/9fd10b4a726cd1f6cc7d812da5575868 to your computer and use it in GitHub Desktop.
Save selevit/9fd10b4a726cd1f6cc7d812da5575868 to your computer and use it in GitHub Desktop.
@fixture(autouse=True, scope='session')
def threadsafe_vcrpy() -> None:
"""This fixture fixes an known VCR.py bug with threading and force_reset():
https://github.com/kevin1024/vcrpy/issues/212
There was a PR for this: https://github.com/kevin1024/vcrpy/pull/300
But the author was not sure if this fix covers all corner cases, and that's why hadn't merge it.
For our needs it's fully enough, that's why we will monkeypatch it until it's not fixed in the lib."""
from vcr.patch import force_reset as original_force_reset
_force_reset_lock = threading.RLock()
@contextmanager
def patched_force_reset():
with _force_reset_lock, original_force_reset():
yield
patcher = patch('vcr.patch.force_reset', patched_force_reset)
patcher.start()
yield
patcher.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment