Repository navigation
Commit 843d5f6
fix(statistics): Show only file names in error groups on Windows (#2515)
### Description
- `ErrorTracker._get_file_and_line` cut the frame filename with
`split("/")`. On Windows the filename has backslashes, so the error
group held the whole path (`C:\...\crawl_job.py:2:ValueError:boom`)
instead of the file name (`crawl_job.py:2:ValueError:boom`). It now uses
`Path(filename).name`.
- `test_error_tracker_similar_messages_full_stack` built its expected
value with the same `__file__.split('/')[-1]`, so it passed on Windows
with the bug in place. It now uses `Path(__file__).name`.
- Adds `test_error_tracker_shows_file_name_without_directories`, which
compiles code with a filename built by `os.path.join`, so the path has
the separator of the platform.
Behavior changes:
- On Windows the error group name, and so the keys of
`get_most_common_errors()` and the hash in the error snapshot file name,
change from a full path to a file name. Linux and macOS are unchanged.
- Two errors raised in different folders but in files with the same name
now share a group on Windows, as they already do on Linux and macOS.
### Issues
- Closes: #2514
### Testing
- `pytest tests/unit/_statistics/test_error_tracker.py` on Windows 11,
Python 3.14: 17 passed. With only the source change reverted, 4 fail
(the new test and the 3 cases of
`test_error_tracker_similar_messages_full_stack`, whose expected value
now holds the file name).
- `pytest tests/unit/_statistics tests/unit/crawlers/_basic`: 161
passed, 1 skipped (the existing skip for issue 908).
- `ruff check` and `ruff format --check` pass on the changed files.
- Compared the old code, the new code and `ntpath.basename` on 100000
generated frame filenames (backslash, slash and mixed separators, drive
letters, UNC paths, relative paths, `<string>`, non-ASCII names). The
old code differs on 67425 of them on Windows, the new code on none. No
input that worked before fails now.
### Checklist
- [x] CI passed
Validated with Claude Opus 5.5.
---------
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>1 parent 24cadc8 commit 843d5f6
2 files changed
Lines changed: 17 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
114 | | - | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | | - | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
86 | 100 | | |
87 | 101 | | |
88 | 102 | | |
| |||
0 commit comments