`logging.captureWarnings` and `warnings.catch_warnings` do not play well together
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
When logging.captureWarnings(True) is called within a warnings.catch_warnings(record=True) context warnings emitted during the context are not recorded.
import logging, warnings
with warnings.catch_warnings(record=True) as rec:
logging.captureWarnings(True)
warnings.warn("foo")
assert len(rec) == 1 # fails since len(rec) == 0
one work-around for this is to enable captureWarnings outside the context
import logging, warnings
logging.captureWarnings(True)
with warnings.catch_warnings(record=True) as rec:
warnings.warn("foo")
assert len(rec) == 1
I tested the above examples on 3.10, 3.13 and 3.14.0b2.
However on 3.14.0b2 with PYTHON_CONTEXT_AWARE_WARNINGS=1 (to pull in the changes from https://github.com/python/cpython/pull/130010) the second example (enabling captureWarnings outside the catch_warnings) no longer works.
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo gli esempi con logging.captureWarnings(True) insieme a warnings.catch_warnings(record=True), includendo PYTHON_CONTEXT_AWARE_WARNINGS=1. Traccia l’interazione tra queste due API e verifica che gli avvisi emessi nel contesto vengano registrati in entrambe le configurazioni descritte nel report.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100