@@ -194,10 +194,92 @@ uv add --dev aiosqlite
194194
195195## Performance
196196
197- Current test execution time: ~ 0.4-0.6 seconds for all 75 tests
197+ Current test execution time (1036 tests total):
198+ - ** Collection** : ~ 1.18s
199+ - ** Sequential execution** : ~ 23s
200+ - ** Parallel execution** (` pytest -n auto ` ): ~ 10s (58% faster)
198201
199- - Unit tests: ~ 0.1s
200- - Integration tests: ~ 0.3s (includes database setup/teardown)
202+ ### Performance Optimizations
203+
204+ Following best practices from [ awesome-pytest-speedup] ( https://github.com/zupo/awesome-pytest-speedup ) , we've implemented several optimizations:
205+
206+ #### 1. PYTHONDONTWRITEBYTECODE=1
207+ - ** Impact** : Reduces I/O overhead during test runs
208+ - ** Location** : Scoped to test targets in ` Makefile ` , set globally in ` .github/workflows/ci.yml `
209+ - Prevents ` .pyc ` file generation during testing
210+ - ** Note** : NOT set globally to avoid affecting dev servers, Docker builds, and other targets that benefit from .pyc caching
211+
212+ #### 2. Disabled Unnecessary Builtin Plugins
213+ - ** Impact** : Faster collection
214+ - ** Disabled** : ` doctest ` , ` pastebin ` , ` legacypath `
215+ - ** Config** : ` pyproject.toml ` → ` addopts `
216+
217+ #### 3. Collection Optimization
218+ - ** Impact** : 25% faster collection
219+ - ** Method** : ` norecursedirs ` excludes ` .git ` , ` node_modules ` , ` docs ` , ` .venv ` , etc.
220+ - ** Config** : ` pyproject.toml ` → ` norecursedirs `
221+
222+ #### 4. Network Access Prevention (pytest-socket)
223+ - ** Impact** : Catches inadvertent network calls in unit tests
224+ - ** Usage** : Tests needing network access: ` @pytest.mark.enable_socket `
225+ - ** Config** : ` --disable-socket --allow-unix-socket ` (allows DB connections)
226+
227+ #### 5. Parallel Execution (pytest-xdist)
228+ - ** Impact** : 58% faster execution on multi-core systems
229+ - ** Usage** : ` pytest -n auto ` (opt-in, not default)
230+ - ** Note** : Some tests may have race conditions when run in parallel
231+
232+ ### Performance Comparison
233+
234+ ```
235+ ┌─────────────────────────────────────────────────────────────┐
236+ │ Pytest Performance Metrics (1036 tests) │
237+ ├─────────────────────────────────────────────────────────────┤
238+ │ │
239+ │ Collection Time: │
240+ │ ├─ Before: 1.58s ████████████████ │
241+ │ └─ After: 1.18s ███████████▓ (-25%) │
242+ │ │
243+ │ Test Execution: │
244+ │ ├─ Sequential: ~23s ██████████████████████████████████ │
245+ │ └─ Parallel: ~10s █████████████▓ (-58%) │
246+ │ │
247+ │ Total Time (with parallel): │
248+ │ ├─ Before: ~25s ██████████████████████████████████ │
249+ │ └─ After: ~11s ██████████████▓ (-56%) │
250+ │ │
251+ └─────────────────────────────────────────────────────────────┘
252+ ```
253+
254+ ### Running Tests with Parallelization
255+
256+ ``` bash
257+ # Default: Sequential (safer, no race conditions)
258+ make test
259+
260+ # Parallel: Use all CPU cores (faster)
261+ pytest -n auto
262+
263+ # Parallel: Use specific number of workers
264+ pytest -n 4
265+
266+ # Quick feedback: Run only failed tests
267+ pytest --lf
268+
269+ # Quick feedback: Run failed first, then rest
270+ pytest --ff
271+ ```
272+
273+ ** Note** : If tests fail with ` -n auto ` but pass sequentially, this indicates race conditions or shared state between tests.
274+
275+ ### Future Optimization Opportunities
276+
277+ Based on [ awesome-pytest-speedup] ( https://github.com/zupo/awesome-pytest-speedup ) :
278+
279+ 1 . ** Database optimization** : Use transaction rollback pattern instead of recreation
280+ 2 . ** Selective execution** : ` pytest-testmon ` to run only tests affected by code changes
281+ 3 . ** Test categorization** : ` pytest-skip-slow ` to skip slow tests by default
282+ 4 . ** CI parallelization** : ` pytest-split ` to distribute tests across multiple CI runners
201283
202284## Documentation
203285
0 commit comments