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)
[x] All tests passing
[x] Added a changelog entry
[N/A] Extended the README / documentation, if necessary
Description
This PR defers importing
_vcr
inplugin.py
until thevcr
fixture is invoked with a vcr-marked test. Themerge_kwargs
helper has been moved toutils.py
to allow importing it independently of the VCR modules required by_vcr.py
. VCR object imports are now guarded usingif 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@pytest.mark.vcr
RuntimeThe 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