|
| 1 | +# Lessons Learned: Improve Test Coverage |
| 2 | + |
| 3 | +**Version**: v0.32.1 |
| 4 | +**Date**: January 2025 |
| 5 | +**Related Brief**: `v0.32.1__dev-brief__improve-test-coverage.md` |
| 6 | +**Related Debrief**: `v0.32.1__debrief__improve-test-coverage.md` |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## User Guidance Received During Session |
| 11 | + |
| 12 | +This document captures the specific guidance and corrections provided by the developer during the test coverage improvement session. These patterns should be followed in future sessions. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## 1. Bug Documentation Convention |
| 17 | + |
| 18 | +### Guidance Received |
| 19 | + |
| 20 | +When discovering bugs during testing: |
| 21 | + |
| 22 | +**a) Naming Convention**: Add `__bug__` to the test method name |
| 23 | + |
| 24 | +```python |
| 25 | +# Instead of: |
| 26 | +def test__enhance_with_signature__type_safe_detection(self): |
| 27 | + |
| 28 | +# Use: |
| 29 | +def test__bug__enhance_with_signature__type_safe_detection(self): |
| 30 | +``` |
| 31 | + |
| 32 | +**b) Comment Format**: Prefix bug comments with `todo:` for IDE visibility |
| 33 | + |
| 34 | +```python |
| 35 | +# Instead of: |
| 36 | +# Note: The actual _enhance_with_signature has a bug where... |
| 37 | +assert endpoint.request_schema is None # BUG: stays None |
| 38 | + |
| 39 | +# Use: |
| 40 | +# todo: BUG: The actual _enhance_with_signature tries to set request_schema |
| 41 | +# to a string but schema expects Type. Exception is silently caught. |
| 42 | +assert endpoint.request_schema is None # todo: BUG: stays None due to type mismatch |
| 43 | +``` |
| 44 | + |
| 45 | +**Reason**: The `todo:` prefix makes bugs visible in PyCharm's TODO panel, making them easier to track and fix later. |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## 2. Import Organization |
| 50 | + |
| 51 | +### Guidance Received |
| 52 | + |
| 53 | +Never add imports inline within test methods. Always add them at the module level with correct alignment. |
| 54 | + |
| 55 | +```python |
| 56 | +# Instead of: |
| 57 | +def test__enhance_with_signature__with_path_param_update(self): |
| 58 | + with self.extractor as _: |
| 59 | + from osbot_fast_api.client.schemas.enums.Enum__Param__Location import Enum__Param__Location |
| 60 | + # ... test code |
| 61 | + |
| 62 | +# Use: |
| 63 | +from osbot_fast_api.client.schemas.enums.Enum__Param__Location import Enum__Param__Location |
| 64 | + |
| 65 | +def test__enhance_with_signature__with_path_param_update(self): |
| 66 | + with self.extractor as _: |
| 67 | + # ... test code |
| 68 | +``` |
| 69 | + |
| 70 | +**Reason**: Keeps imports organized and consistent with project conventions. Imports should be alphabetically sorted and aligned. |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## 3. Document Separation |
| 75 | + |
| 76 | +### Guidance Received (from Session 1) |
| 77 | + |
| 78 | +Keep the original dev-brief document unchanged as a historical record of the plan. Create a separate debrief document to track progress and capture what was actually done. |
| 79 | + |
| 80 | +**Document Structure**: |
| 81 | +- `v0.32.1__dev-brief__*.md` - Original plan (immutable after creation) |
| 82 | +- `v0.32.1__debrief__*.md` - Progress tracking, stats, session log |
| 83 | +- `v0.32.1__lessons-learned__*.md` - Guidance received, patterns learned |
| 84 | + |
| 85 | +**Reason**: Preserves the original intent and allows comparison between planned vs actual work. |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## 4. Type_Safe Testing Patterns |
| 90 | + |
| 91 | +### From Project Guidance Documents |
| 92 | + |
| 93 | +The project has specific testing conventions documented in `docs/llm-briefs/type_safety/`: |
| 94 | + |
| 95 | +**Context Manager Pattern**: |
| 96 | +```python |
| 97 | +def test_something(self): |
| 98 | + with SomeClass() as _: |
| 99 | + assert _.field == expected_value |
| 100 | +``` |
| 101 | + |
| 102 | +**Inline Comments (Not Docstrings)**: |
| 103 | +```python |
| 104 | +def test_something(self): # Brief description of test |
| 105 | + with SomeClass() as _: |
| 106 | + result = _.method() # explain what this does |
| 107 | + assert result == expected # explain the assertion |
| 108 | +``` |
| 109 | + |
| 110 | +**Method Naming**: |
| 111 | +``` |
| 112 | +test__<method_name>__<scenario> |
| 113 | +``` |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## Summary of Key Patterns |
| 118 | + |
| 119 | +| Pattern | Convention | |
| 120 | +|---------|------------| |
| 121 | +| Bug tests | Prefix with `test__bug__` | |
| 122 | +| Bug comments | Use `# todo: BUG:` prefix | |
| 123 | +| Imports | Module level only, aligned | |
| 124 | +| Dev docs | Separate brief/debrief/lessons | |
| 125 | +| Folder names | Don't hardcode, be flexible | |
| 126 | +| Test style | Context manager with `_`, inline comments | |
0 commit comments