pytest-deltatest 0.4.38__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. pytest_deltatest-0.4.38/PKG-INFO +277 -0
  2. pytest_deltatest-0.4.38/README.md +250 -0
  3. pytest_deltatest-0.4.38/delta/__init__.py +14 -0
  4. pytest_deltatest-0.4.38/delta/build_mapping_iterative.py +467 -0
  5. pytest_deltatest-0.4.38/delta/cli.py +1378 -0
  6. pytest_deltatest-0.4.38/delta/cloud_mapping_db.py +339 -0
  7. pytest_deltatest-0.4.38/delta/config.py +149 -0
  8. pytest_deltatest-0.4.38/delta/coverage_mapper.py +365 -0
  9. pytest_deltatest-0.4.38/delta/git_diff_parser.py +256 -0
  10. pytest_deltatest-0.4.38/delta/pre_commit_hook.py +1471 -0
  11. pytest_deltatest-0.4.38/delta/push_cache.py +73 -0
  12. pytest_deltatest-0.4.38/delta/pytest_plugin.py +233 -0
  13. pytest_deltatest-0.4.38/delta/range_set.py +173 -0
  14. pytest_deltatest-0.4.38/delta/test_mapping_db_v2.py +419 -0
  15. pytest_deltatest-0.4.38/delta/update_mapping.py +167 -0
  16. pytest_deltatest-0.4.38/pytest_deltatest.egg-info/PKG-INFO +277 -0
  17. pytest_deltatest-0.4.38/pytest_deltatest.egg-info/SOURCES.txt +25 -0
  18. pytest_deltatest-0.4.38/pytest_deltatest.egg-info/dependency_links.txt +1 -0
  19. pytest_deltatest-0.4.38/pytest_deltatest.egg-info/entry_points.txt +5 -0
  20. pytest_deltatest-0.4.38/pytest_deltatest.egg-info/requires.txt +4 -0
  21. pytest_deltatest-0.4.38/pytest_deltatest.egg-info/top_level.txt +1 -0
  22. pytest_deltatest-0.4.38/setup.cfg +4 -0
  23. pytest_deltatest-0.4.38/setup.py +40 -0
  24. pytest_deltatest-0.4.38/tests/test_cli_e2e.py +470 -0
  25. pytest_deltatest-0.4.38/tests/test_git_diff_parser.py +60 -0
  26. pytest_deltatest-0.4.38/tests/test_new_feature.py +1 -0
  27. pytest_deltatest-0.4.38/tests/test_range_set.py +261 -0
@@ -0,0 +1,277 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytest-deltatest
3
+ Version: 0.4.38
4
+ Summary: Run only the tests affected by your code changes.
5
+ Author: Delta Contributors
6
+ Classifier: Development Status :: 3 - Alpha
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: Framework :: Pytest
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.8
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: pytest>=7.0.0
17
+ Requires-Dist: pytest-cov>=4.0.0
18
+ Requires-Dist: coverage[toml]>=7.0.0
19
+ Requires-Dist: requests>=2.25.0
20
+ Dynamic: author
21
+ Dynamic: classifier
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: requires-dist
25
+ Dynamic: requires-python
26
+ Dynamic: summary
27
+
28
+ # Delta
29
+
30
+ **Run only the tests affected by your code changes** - automatically!
31
+
32
+ Delta integrates with your git workflow as a pre-commit hook, running only tests that cover the code you've changed. This dramatically speeds up your development cycle while ensuring quality.
33
+
34
+ ## Key Features
35
+
36
+ - **Fast**: Run only affected tests, not the entire suite
37
+ - **Safe**: Blocks commits if affected tests fail
38
+ - **Intelligent**: Uses SQLite-based test-to-code mapping for instant lookups
39
+ - **Incremental Coverage**: Combines coverage from test runs
40
+ - **New Test Detection**: Always runs newly added tests
41
+ - **Auto-Discovery**: Detects unmapped tests and builds mapping automatically
42
+ - **Pre-commit Hook**: Automatic integration with git workflow
43
+ - **Status Check**: Instantly inspect database mapping stats (both local and cloud via [deltatest.dev](https://deltatest.dev))
44
+ - **Delta Cloud Sync**: Share test mappings across CI/CD and teams automatically (Powered by [deltatest.dev](https://deltatest.dev))
45
+
46
+ ## Quick Start (Pre-Commit Hook)
47
+
48
+ ```bash
49
+ cd ~/workspace/myproject
50
+
51
+ # Install the pre-commit hook
52
+ delta install
53
+
54
+ # That's it! Now every commit will:
55
+ # 1. Find tests affected by your changes
56
+ # 2. Run only those tests
57
+ # 3. Block commit if tests fail
58
+ # 4. Combine coverage with existing data
59
+ ```
60
+
61
+ ## 📋 How It Works
62
+
63
+ ### Pre-Commit Flow
64
+
65
+ ```
66
+ Developer commits changes
67
+ ↓
68
+ Pre-commit hook triggered
69
+ ↓
70
+ Compare staged changes vs development branch
71
+ ↓
72
+ Query SQLite mapping: "Which tests cover these lines?"
73
+ ↓
74
+ Detect unmapped tests (dry-run pytest --collect-only)
75
+ ↓
76
+ Run unmapped tests all-at-once (build mapping)
77
+ ↓
78
+ Run mapped affected tests with coverage
79
+ ↓
80
+ Tests pass? → Combine coverage → Allow commit
81
+ Tests fail? → Block commit
82
+ ```
83
+
84
+ ### Auto-Discovery of Unmapped Tests
85
+
86
+ The pre-commit hook automatically detects tests that exist in your codebase but aren't in the mapping database yet:
87
+
88
+ 1. **Collect all tests**: Runs `pytest --collect-only` to find all available tests
89
+ 2. **Compare with mapping**: Queries `.delta/test_mapping.db` to see which tests are already mapped
90
+ 3. **Find delta**: Identifies tests that exist but have never been run with coverage
91
+ 4. **Run all-at-once**: Executes all unmapped tests together with `--cov-context=test` (fastest)
92
+ 5. **Update mapping**: After completion, updates the mapping database with new coverage
93
+
94
+ **Why this matters:**
95
+ - New tests you write are automatically added to the mapping
96
+ - Tests added by teammates get mapped when you first commit
97
+ - No need to manually regenerate the entire mapping
98
+ - Mapping database grows organically over time
99
+ - All tests run in a single pytest invocation (fastest possible)
100
+
101
+ **Example:**
102
+
103
+ ```bash
104
+ $ git commit -m "Fix bug in auth.py"
105
+
106
+ Found 1 changed Python file
107
+ Mapping DB: 1234 tests, 567 files, 45678 mappings
108
+ Collected 1250 total tests from pytest
109
+ Found 16 unmapped test(s)
110
+
111
+ ================================================================================
112
+ Building coverage mapping for 16 unmapped test(s)
113
+ ================================================================================
114
+
115
+ Running unmapped test: unit_tests/test_new_feature.py::test_case_1
116
+ ✓ Mapping updated for: unit_tests/test_new_feature.py::test_case_1
117
+ Running unmapped test: unit_tests/test_new_feature.py::test_case_2
118
+ ✓ Mapping updated for: unit_tests/test_new_feature.py::test_case_2
119
+ ...
120
+ ✓ Successfully mapped 16 test(s)
121
+
122
+ ================================================================================
123
+ Running 3 affected test(s)...
124
+ ================================================================================
125
+ ...
126
+ ```
127
+
128
+ ### Mapping Database
129
+
130
+ The mapping is stored in `.delta/test_mapping.db` (SQLite) at your repo root:
131
+
132
+ ```sql
133
+ CREATE TABLE test_coverage_ranges (
134
+ test_name TEXT NOT NULL,
135
+ file_path TEXT NOT NULL,
136
+ ranges TEXT NOT NULL,
137
+ PRIMARY KEY (test_name, file_path)
138
+ );
139
+ ```
140
+
141
+ Fast lookups: "Which tests cover file X, line Y?"
142
+
143
+ ## Installation
144
+
145
+ ### Prerequisites
146
+
147
+ - Python 3.8+
148
+ - pytest >= 7.0
149
+ - pytest-cov >= 4.0
150
+ - Git repository
151
+
152
+ ### Step 1: Install Package
153
+
154
+ Install via pip:
155
+
156
+ ```bash
157
+ pip install deltatest-cli
158
+ ```
159
+
160
+ ### Step 2: Build Mapping Database
161
+
162
+ ```bash
163
+ cd ~/workspace/myproject
164
+
165
+ # Build mapping database (resumable)
166
+ delta build-mapping --verbose
167
+ ```
168
+
169
+ ### Step 3: Install Pre-Commit Hook
170
+
171
+ ```bash
172
+ cd ~/workspace/myproject
173
+ delta install
174
+ ```
175
+
176
+ Done! Now every commit will run only affected tests.
177
+
178
+ ## Usage
179
+
180
+ ### Pre-Commit Hook (Automatic)
181
+
182
+ Just commit normally:
183
+
184
+ ```bash
185
+ git add src/my_module.py
186
+ git commit -m "Fix bug in authentication"
187
+
188
+ # Hook runs automatically:
189
+ # - Finds tests covering src/my_module.py
190
+ # - Runs only those tests
191
+ # - Blocks commit if tests fail
192
+ # - Combines coverage on success
193
+ ```
194
+
195
+ ### Manual Test Running
196
+
197
+ ```bash
198
+ # Show what tests would run
199
+ delta run --dry-run --verbose
200
+
201
+ # Run affected tests manually
202
+ delta run
203
+
204
+ # Compare against different branch
205
+ delta run --base-branch develop
206
+
207
+ # Pass pytest arguments
208
+ delta run -- -x --pdb
209
+ ```
210
+
211
+ ### Check Mapping Status
212
+
213
+ You can inspect the status and statistics of the local mapping database and the remote mapping service ([deltatest.dev](https://deltatest.dev)):
214
+
215
+ ```bash
216
+ delta status
217
+ ```
218
+
219
+ ## Commands
220
+
221
+ ### `delta run`
222
+
223
+ Run affected tests based on changes.
224
+
225
+ ```bash
226
+ delta run [OPTIONS] [-- PYTEST_ARGS]
227
+
228
+ Options:
229
+ --repo-root PATH Repository root (default: current directory)
230
+ --local, --no-remote Run locally without connecting to the deltatest.dev remote mapping service
231
+ --base-branch BRANCH Branch to compare against (default: master)
232
+ --coverage-file PATH Path to .coverage file
233
+ --dry-run Show tests without running
234
+ --min-tests N Minimum tests required
235
+ --explain Show exactly which tests are affected by which files/lines
236
+ -v, --verbose Detailed output
237
+ ```
238
+
239
+ ### `delta build-mapping`
240
+
241
+ Build test mapping database iteratively.
242
+
243
+ ```bash
244
+ delta build-mapping [OPTIONS]
245
+
246
+ Options:
247
+ --repo-root PATH Repository root (default: current directory)
248
+ --local, --no-remote Build mapping database locally without remote deltatest.dev connection
249
+ --mapping-db PATH Path to mapping database
250
+ --test-dir PATH Directory containing tests
251
+ -v, --verbose Detailed output
252
+ ```
253
+
254
+ ### `delta status`
255
+
256
+ Show local and remote (deltatest.dev) database status and statistics.
257
+
258
+ ```bash
259
+ delta status [OPTIONS]
260
+
261
+ Options:
262
+ --repo-root PATH Repository root (default: current directory)
263
+ --mapping-db PATH Path to mapping database
264
+ -v, --verbose Detailed output
265
+ ```
266
+
267
+ ## Bypassing the Hook
268
+
269
+ For urgent commits:
270
+
271
+ ```bash
272
+ git commit --no-verify -m "Urgent hotfix"
273
+ ```
274
+
275
+ ## Contributing
276
+
277
+ Delta is an open-source developer productivity tool.
@@ -0,0 +1,250 @@
1
+ # Delta
2
+
3
+ **Run only the tests affected by your code changes** - automatically!
4
+
5
+ Delta integrates with your git workflow as a pre-commit hook, running only tests that cover the code you've changed. This dramatically speeds up your development cycle while ensuring quality.
6
+
7
+ ## Key Features
8
+
9
+ - **Fast**: Run only affected tests, not the entire suite
10
+ - **Safe**: Blocks commits if affected tests fail
11
+ - **Intelligent**: Uses SQLite-based test-to-code mapping for instant lookups
12
+ - **Incremental Coverage**: Combines coverage from test runs
13
+ - **New Test Detection**: Always runs newly added tests
14
+ - **Auto-Discovery**: Detects unmapped tests and builds mapping automatically
15
+ - **Pre-commit Hook**: Automatic integration with git workflow
16
+ - **Status Check**: Instantly inspect database mapping stats (both local and cloud via [deltatest.dev](https://deltatest.dev))
17
+ - **Delta Cloud Sync**: Share test mappings across CI/CD and teams automatically (Powered by [deltatest.dev](https://deltatest.dev))
18
+
19
+ ## Quick Start (Pre-Commit Hook)
20
+
21
+ ```bash
22
+ cd ~/workspace/myproject
23
+
24
+ # Install the pre-commit hook
25
+ delta install
26
+
27
+ # That's it! Now every commit will:
28
+ # 1. Find tests affected by your changes
29
+ # 2. Run only those tests
30
+ # 3. Block commit if tests fail
31
+ # 4. Combine coverage with existing data
32
+ ```
33
+
34
+ ## 📋 How It Works
35
+
36
+ ### Pre-Commit Flow
37
+
38
+ ```
39
+ Developer commits changes
40
+ ↓
41
+ Pre-commit hook triggered
42
+ ↓
43
+ Compare staged changes vs development branch
44
+ ↓
45
+ Query SQLite mapping: "Which tests cover these lines?"
46
+ ↓
47
+ Detect unmapped tests (dry-run pytest --collect-only)
48
+ ↓
49
+ Run unmapped tests all-at-once (build mapping)
50
+ ↓
51
+ Run mapped affected tests with coverage
52
+ ↓
53
+ Tests pass? → Combine coverage → Allow commit
54
+ Tests fail? → Block commit
55
+ ```
56
+
57
+ ### Auto-Discovery of Unmapped Tests
58
+
59
+ The pre-commit hook automatically detects tests that exist in your codebase but aren't in the mapping database yet:
60
+
61
+ 1. **Collect all tests**: Runs `pytest --collect-only` to find all available tests
62
+ 2. **Compare with mapping**: Queries `.delta/test_mapping.db` to see which tests are already mapped
63
+ 3. **Find delta**: Identifies tests that exist but have never been run with coverage
64
+ 4. **Run all-at-once**: Executes all unmapped tests together with `--cov-context=test` (fastest)
65
+ 5. **Update mapping**: After completion, updates the mapping database with new coverage
66
+
67
+ **Why this matters:**
68
+ - New tests you write are automatically added to the mapping
69
+ - Tests added by teammates get mapped when you first commit
70
+ - No need to manually regenerate the entire mapping
71
+ - Mapping database grows organically over time
72
+ - All tests run in a single pytest invocation (fastest possible)
73
+
74
+ **Example:**
75
+
76
+ ```bash
77
+ $ git commit -m "Fix bug in auth.py"
78
+
79
+ Found 1 changed Python file
80
+ Mapping DB: 1234 tests, 567 files, 45678 mappings
81
+ Collected 1250 total tests from pytest
82
+ Found 16 unmapped test(s)
83
+
84
+ ================================================================================
85
+ Building coverage mapping for 16 unmapped test(s)
86
+ ================================================================================
87
+
88
+ Running unmapped test: unit_tests/test_new_feature.py::test_case_1
89
+ ✓ Mapping updated for: unit_tests/test_new_feature.py::test_case_1
90
+ Running unmapped test: unit_tests/test_new_feature.py::test_case_2
91
+ ✓ Mapping updated for: unit_tests/test_new_feature.py::test_case_2
92
+ ...
93
+ ✓ Successfully mapped 16 test(s)
94
+
95
+ ================================================================================
96
+ Running 3 affected test(s)...
97
+ ================================================================================
98
+ ...
99
+ ```
100
+
101
+ ### Mapping Database
102
+
103
+ The mapping is stored in `.delta/test_mapping.db` (SQLite) at your repo root:
104
+
105
+ ```sql
106
+ CREATE TABLE test_coverage_ranges (
107
+ test_name TEXT NOT NULL,
108
+ file_path TEXT NOT NULL,
109
+ ranges TEXT NOT NULL,
110
+ PRIMARY KEY (test_name, file_path)
111
+ );
112
+ ```
113
+
114
+ Fast lookups: "Which tests cover file X, line Y?"
115
+
116
+ ## Installation
117
+
118
+ ### Prerequisites
119
+
120
+ - Python 3.8+
121
+ - pytest >= 7.0
122
+ - pytest-cov >= 4.0
123
+ - Git repository
124
+
125
+ ### Step 1: Install Package
126
+
127
+ Install via pip:
128
+
129
+ ```bash
130
+ pip install deltatest-cli
131
+ ```
132
+
133
+ ### Step 2: Build Mapping Database
134
+
135
+ ```bash
136
+ cd ~/workspace/myproject
137
+
138
+ # Build mapping database (resumable)
139
+ delta build-mapping --verbose
140
+ ```
141
+
142
+ ### Step 3: Install Pre-Commit Hook
143
+
144
+ ```bash
145
+ cd ~/workspace/myproject
146
+ delta install
147
+ ```
148
+
149
+ Done! Now every commit will run only affected tests.
150
+
151
+ ## Usage
152
+
153
+ ### Pre-Commit Hook (Automatic)
154
+
155
+ Just commit normally:
156
+
157
+ ```bash
158
+ git add src/my_module.py
159
+ git commit -m "Fix bug in authentication"
160
+
161
+ # Hook runs automatically:
162
+ # - Finds tests covering src/my_module.py
163
+ # - Runs only those tests
164
+ # - Blocks commit if tests fail
165
+ # - Combines coverage on success
166
+ ```
167
+
168
+ ### Manual Test Running
169
+
170
+ ```bash
171
+ # Show what tests would run
172
+ delta run --dry-run --verbose
173
+
174
+ # Run affected tests manually
175
+ delta run
176
+
177
+ # Compare against different branch
178
+ delta run --base-branch develop
179
+
180
+ # Pass pytest arguments
181
+ delta run -- -x --pdb
182
+ ```
183
+
184
+ ### Check Mapping Status
185
+
186
+ You can inspect the status and statistics of the local mapping database and the remote mapping service ([deltatest.dev](https://deltatest.dev)):
187
+
188
+ ```bash
189
+ delta status
190
+ ```
191
+
192
+ ## Commands
193
+
194
+ ### `delta run`
195
+
196
+ Run affected tests based on changes.
197
+
198
+ ```bash
199
+ delta run [OPTIONS] [-- PYTEST_ARGS]
200
+
201
+ Options:
202
+ --repo-root PATH Repository root (default: current directory)
203
+ --local, --no-remote Run locally without connecting to the deltatest.dev remote mapping service
204
+ --base-branch BRANCH Branch to compare against (default: master)
205
+ --coverage-file PATH Path to .coverage file
206
+ --dry-run Show tests without running
207
+ --min-tests N Minimum tests required
208
+ --explain Show exactly which tests are affected by which files/lines
209
+ -v, --verbose Detailed output
210
+ ```
211
+
212
+ ### `delta build-mapping`
213
+
214
+ Build test mapping database iteratively.
215
+
216
+ ```bash
217
+ delta build-mapping [OPTIONS]
218
+
219
+ Options:
220
+ --repo-root PATH Repository root (default: current directory)
221
+ --local, --no-remote Build mapping database locally without remote deltatest.dev connection
222
+ --mapping-db PATH Path to mapping database
223
+ --test-dir PATH Directory containing tests
224
+ -v, --verbose Detailed output
225
+ ```
226
+
227
+ ### `delta status`
228
+
229
+ Show local and remote (deltatest.dev) database status and statistics.
230
+
231
+ ```bash
232
+ delta status [OPTIONS]
233
+
234
+ Options:
235
+ --repo-root PATH Repository root (default: current directory)
236
+ --mapping-db PATH Path to mapping database
237
+ -v, --verbose Detailed output
238
+ ```
239
+
240
+ ## Bypassing the Hook
241
+
242
+ For urgent commits:
243
+
244
+ ```bash
245
+ git commit --no-verify -m "Urgent hotfix"
246
+ ```
247
+
248
+ ## Contributing
249
+
250
+ Delta is an open-source developer productivity tool.
@@ -0,0 +1,14 @@
1
+ """Delta - Run only tests affected by code changes."""
2
+
3
+ __version__ = "0.4.36"
4
+ __author__ = "Delta Contributors"
5
+ __description__ = "Intelligently select and run only tests affected by code changes"
6
+
7
+ # Range-based storage (v2)
8
+ from .test_mapping_db_v2 import TestMappingDBV2
9
+ from .range_set import RangeSet
10
+
11
+ __all__ = [
12
+ "TestMappingDBV2", # New range-based storage
13
+ "RangeSet", # Range compression utility
14
+ ]