Skip to content

Commit a520b52

Browse files
authored
pytest plugin: Improve performance via caching (#472)
# Problem Git, Mercurial, and Subversion repositories are unnecessarily reinitialized for each test. - We're not utilizing session-based scoping. - A single initial repo could be created, then copied to [`tmp_path`](https://docs.pytest.org/en/8.3.x/how-to/tmp_path.html#the-tmp-path-fixture) using [`shutil.copytree`](https://docs.python.org/3/library/shutil.html#shutil.copytree) ([source](https://github.com/python/cpython/blob/v3.13.0/Lib/shutil.py#L550-L605)). Issue #471 highlighted this inefficiency, where benchmarks showed tens of thousands of redundant functional calls. # Improvement ``` ❯ hyperfine -L branch master,pytest-plugin-fixture-caching 'git checkout {branch} && py.test' Benchmark 1: git checkout master && py.test Time (mean ± σ): 32.062 s ± 0.869 s [User: 41.391 s, System: 9.931 s] Range (min … max): 30.878 s … 33.583 s 10 runs Benchmark 2: git checkout pytest-plugin-fixture-caching && py.test Time (mean ± σ): 14.659 s ± 0.495 s [User: 16.351 s, System: 4.433 s] Range (min … max): 13.990 s … 15.423 s 10 runs Summary git checkout pytest-plugin-fixture-caching && py.test ran 2.19 ± 0.09 times faster than git checkout master && py.test ``` # Changes ## Pytest fixtures overhaul 1. Create a base VCS repo. 2. For subsequent tests, copy and modify from this template.
2 parents bc6e897 + a658c43 commit a520b52

File tree

6 files changed

+329
-78
lines changed

6 files changed

+329
-78
lines changed

CHANGES

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ $ pip install --user --upgrade --pre libvcs
1717

1818
### Breaking changes
1919

20+
#### pytest plugin: Improve performacne via session-based scoping (#472)
21+
22+
Improved test execution speed by over 54% by eliminated repetitive repository reinitialization between test runs.
23+
Git, Subversion, and Mercurial repositories are now cached from an initial starter repository
24+
2025
#### pytest fixtures: `git_local_clone` renamed to `example_git_repo` (#468)
2126

2227
Renamed `git_local_clone` to `example_git_repo` for better understandability in

0 commit comments

Comments
 (0)