Commit db801ad
fix(oauth): cover Python 3.10/3.11 partial-branch coverage gap
On Python 3.10/3.11, coverage.py (sys.settrace backend) misattributes
the False arm of compound boolean predicates inside an async with block
in an async generator, leading to spurious partial-branch warnings on
4 lines in async_auth_flow:
- line 536: `if not is_token_valid() and can_refresh_token():` (Phase 1)
- line 546: same (Phase 2 double-check inside refresh_lock)
- line 548: `if refresh_request is not None:` (re-check skip path)
- line 553: `if not await _handle_refresh_response(...):` (refresh
success path)
Python 3.12+ (sys.monitoring) tracks these branches correctly. Add
`# pragma: no branch` to the 4 lines as a workaround for the legacy
backend only. An inline comment block above the Phase 1 if documents
the rationale.
Also add 2 unit tests that explicitly exercise the affected branches so
the coverage drop is shown to be a tool-precision issue, not missing
tests:
- test_phase1_skips_refresh_when_token_valid:
Phase 1 sees is_token_valid=True and skips Phase 2 entirely.
- test_refresh_success_proceeds_to_phase3_without_resetting_initialized:
_handle_refresh_response returns True (HTTP 200) so the
_initialized reset is skipped and Phase 3 proceeds with the
fresh token.
Local verification (Python 3.10):
pytest tests/client/test_auth.py -n auto + coverage report
→ 99.43% (was 98.30%, BrPart 1, Missing only line 206 which is
outside the test_auth.py scope). Full suite should reach 100%.1 parent 148ec42 commit db801ad
2 files changed
Lines changed: 76 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
532 | 532 | | |
533 | 533 | | |
534 | 534 | | |
535 | | - | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
536 | 541 | | |
537 | 542 | | |
538 | 543 | | |
| |||
542 | 547 | | |
543 | 548 | | |
544 | 549 | | |
545 | | - | |
| 550 | + | |
546 | 551 | | |
547 | | - | |
| 552 | + | |
548 | 553 | | |
549 | 554 | | |
550 | 555 | | |
551 | 556 | | |
552 | | - | |
| 557 | + | |
553 | 558 | | |
554 | 559 | | |
555 | 560 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2836 | 2836 | | |
2837 | 2837 | | |
2838 | 2838 | | |
| 2839 | + | |
| 2840 | + | |
| 2841 | + | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
| 2849 | + | |
| 2850 | + | |
| 2851 | + | |
| 2852 | + | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
| 2859 | + | |
| 2860 | + | |
| 2861 | + | |
| 2862 | + | |
| 2863 | + | |
| 2864 | + | |
| 2865 | + | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
0 commit comments