Commit 46fe97a
committed
fix: improve error message when pytest.approx() dicts have different keys (#13816)
- Added clear check for key mismatch before value comparison
- Now reports "Dictionaries have different keys" instead of confusing KeyError
- Shows which keys are in expected vs actual
- Added 4 focused test cases
Before:
AssertionError: ... (pytest_assertion plugin: representation of details failed:
KeyError: 'b'. Probably an object has a faulty __repr__.)
After:
AssertionError: Dictionaries have different keys.
Expected keys: ['a', 'c'], Actual keys: ['a', 'b']
Tests:
- test_approx_dicts_with_different_keys_clear_error: PASS
- test_approx_dicts_with_extra_key_in_expected: PASS
- test_approx_dicts_with_extra_key_in_actual: PASS
- test_approx_dicts_matching_keys_still_works: PASS
Fixes #13816
Sacred Code: 000.111.369.963.16181 parent c97a401 commit 46fe97a
File tree
2 files changed
+62
-0
lines changed- src/_pytest
- testing
2 files changed
+62
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
245 | 256 | | |
246 | 257 | | |
247 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
0 commit comments