Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: "Lazy load" VCR to reduce plugin overhead #146

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

herbierand
Copy link
Contributor

@herbierand herbierand commented Jul 8, 2024

Description

This PR defers importing _vcr in plugin.py until the vcr fixture is invoked with a vcr-marked test. The merge_kwargs helper has been moved to utils.py to allow importing it independently of the VCR modules required by _vcr.py. VCR object imports are now guarded using if TYPE_CHECKING.

To verify the performance improvement, I compared the results of running the same dummy test case with and without the vcr mark. I averaged results from running pytest 20 times, removing __pycache__ and .pytest_cache between runs. Here is a summary of the results:

pytest_recording version Unmarked Test Runtime @pytest.mark.vcr Runtime
0.13.1 291.47 ms 287.70 ms
This change 140.39 ms 294.15 ms

The results show a significant improvement in the runtime of unmarked tests, while the runtime of tests marked with @pytest.mark.vcr remains comparable to the previous version.

Checklist

  • [N/A] Created tests which fail without the change (if possible)
  • All tests passing
  • Added a changelog entry
  • [N/A] Extended the README / documentation, if necessary

Defer importing `_vcr` in `plugin.py` until the `vcr` fixture is
invoked with a vcr-marked test. Move `merge_kwargs` helper to utils
so it can be imported independently of VCR modules required by
`_vcr.py`. Guard VCR object type hints using `if TYPE_CHECKING`.
@Stranger6667 Stranger6667 merged commit 1797405 into kiwicom:master Jul 9, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants