- Notifications
You must be signed in to change notification settings - Fork11
pytest plugin: Improve performance via caching#472
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
a1cea48 to4e66283Comparecodecovbot commentedOct 12, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## master #472 +/- ##==========================================+ Coverage 63.85% 64.17% +0.32%========================================== Files 40 40 Lines 3591 3713 +122 Branches 774 788 +14 ==========================================+ Hits 2293 2383 +90- Misses 772 793 +21- Partials 526 537 +11 ☔ View full report in Codecov by Sentry. |
e6bcfba toae8e219Compare68a8bd8 to3b4d3c0Compare3b4d3c0 tob7c4149Compareb7c4149 tofaaba05Compare7af8ea6 toa658c43Comparea520b52 intomasterUh oh!
There was an error while loading.Please reload this page.
_Resolves #474_# ProblemIssue#472 requires session-scoped fixtures.Currently, we use `set_home`, `gitconfig`, and `hgconfig` to `monkeypatch.setenv` `$HOME`, pointing it to a temporary directory with user-specific configuration files. This ensures all subsequent `git` and `hg` commands automatically load these configurations.However, [`monkeypatch.setenv`](https://docs.pytest.org/en/8.3.x/reference/reference.html#pytest.MonkeyPatch.setenv) doesn't work with function-scoped fixtures.# Improvement```❯ hyperfine \ --warmup 3 \ --runs 10 \ --prepare 'git checkout master' \ --command-name 'libvcs 0.31.0' \ 'py.test' \ --prepare 'git checkout pytest-config' \ --command-name 'with improved hg/git config fixtures' \ 'py.test'Benchmark 1: libvcs 0.31.0 Time (mean ± σ): 15.150 s ± 0.751 s [User: 16.650 s, System: 4.720 s] Range (min … max): 14.235 s … 16.741 s 10 runsBenchmark 2: with improved hg/git config fixtures Time (mean ± σ): 15.014 s ± 0.307 s [User: 17.246 s, System: 4.865 s] Range (min … max): 14.458 s … 15.642 s 10 runsSummary with improved hg/git config fixtures ran 1.01 ± 0.05 times faster than libvcs 0.31.0```# Changes## pytest fixtures: Session-scoped `hgconfig` and `gitconfig`These are now set by `set_hgconfig` and `set_gitconfig`, which set `HGRCPATH` and `GIT_CONFIG`, instead of overriding `HOME`.
# ProblemGit, Subversion, and Mercurial repositories are unnecessarily reinitialized for each test via libvcs' pytest plugin.- 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)).# Improvement```❯ hyperfine \ --warmup 3 \ --runs 10 \ --prepare 'pip uninstall -y libvcs && pip install "libvcs==0.30.1"' \ --command-name 'libvcs 0.30.1' \ 'py.test' \ --prepare 'pip uninstall -y libvcs && pip install "libvcs==0.31.0"' \ --command-name 'libvcs 0.31.0' \ 'py.test' \ --prepare 'pip uninstall -y libvcs && pip install "libvcs==0.32.1"' \ --command-name 'libvcs 0.32.1' \ 'py.test'Benchmark 1: libvcs 0.30.1 Time (mean ± σ): 4.784 s ± 0.116 s [User: 4.641 s, System: 0.846 s] Range (min … max): 4.599 s … 4.971 s 10 runsBenchmark 2: libvcs 0.31.0 Time (mean ± σ): 3.436 s ± 0.115 s [User: 2.821 s, System: 0.470 s] Range (min … max): 3.347 s … 3.678 s 10 runsBenchmark 3: libvcs 0.32.1 Time (mean ± σ): 3.173 s ± 0.054 s [User: 2.726 s, System: 0.388 s] Range (min … max): 3.104 s … 3.295 s 10 runsSummary libvcs 0.32.1 ran 1.08 ± 0.04 times faster than libvcs 0.31.0 1.51 ± 0.04 times faster than libvcs 0.30.1```# Changes## libvcs 0.30.1 -> 0.32.1See also:-https://github.com/vcs-python/libvcs/blob/v0.32.1/CHANGES#libvcs-0310-2024-10-12-https://libvcs.git-pull.com/history.html#libvcs-0-32-1-2024-10-12# Appendix-vcs-python/libvcs#472
Uh oh!
There was an error while loading.Please reload this page.
Problem
Git, Mercurial, and Subversion repositories are unnecessarily reinitialized for each test.
tmp_pathusingshutil.copytree(source).Issue#471 highlighted this inefficiency, where benchmarks showed tens of thousands of redundant function calls.
Improvement
Changes
Pytest fixtures overhaul