Created
July 12, 2021 08:40
-
-
Save selevit/9fd10b4a726cd1f6cc7d812da5575868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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