`logging.captureWarnings` and `warnings.catch_warnings` do not play well together
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece reproduzindo os exemplos usando logging.captureWarnings(True) com warnings.catch_warnings(record=True), incluindo PYTHON_CONTEXT_AWARE_WARNINGS=1. Rastreie a interação entre essas duas APIs e verifique se os avisos emitidos no contexto são registrados em ambas as configurações descritas pelo relatório.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100