Commit a520b52
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.File tree
6 files changed
+329
-78
lines changed- src/libvcs
- tests
- sync
- url
6 files changed
+329
-78
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
| |||
0 commit comments