Unit tests: invoking the reflex CLI in-process leaves REFLEX_MANAGED_LOGGING=true in os.environ for every later test
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- developer-experience, testing
Línea de trabajo
Empieza por el fixture autouse de tests/units/conftest.py y los ejemplos de restablecimiento del logging en tests/units/reflex_base/utils/test_log.py. Comprueba cómo tests/units/reflex_cli/v2/conftest.py habilita el logging gestionado para que esas pruebas conserven su configuración. El objetivo se cumple cuando cada prueba comienza sin estado residual de REFLEX_MANAGED_LOGGING ni del sink de logging; ejecuta las pruebas unitarias afectadas, incluida una invocación de CLI seguida de una prueba de migración.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Problem
The reflex click group callback (cli() in reflex/reflex.py) calls log.enable_managed_logging(), which sets os.environ["REFLEX_MANAGED_LOGGING"] = "true" and configures the logging sinks. That is correct for the real CLI process, but unit tests that run the CLI in-process with click.testing.CliRunner().invoke(cli, [...]) (about a dozen of them across tests/units/test_reflex.py, tests/units/test_prerequisites.py, tests/units/reflex_cli/v2/test_deploy.py, tests/units/reflex_bench/test_cli.py) never undo it. CliRunner does not isolate os.environ, so every test that runs later in the same pytest process sees managed logging switched on.
This makes test outcomes order-dependent: while working on #7797, a migrations test failed on unmodified main when it ran after one of these CLI tests (it passes on its own). Tests that assert on log output or on whether logging is configured are the ones affected.
Not user-facing; it affects contributors and CI stability.
Repro
Minimal demonstration of the leak (run with the repo's dev environment):
import os
from click.testing import CliRunner
from reflex.reflex import cli
print("before:", os.environ.get("REFLEX_MANAGED_LOGGING")) # None
CliRunner().invoke(cli, ["db", "--help"])
print("after:", os.environ.get("REFLEX_MANAGED_LOGGING")) # 'true'
To find the affected test pair, run the unit suite with a random or reversed order (for example uv run pytest tests/units -p randomly with pytest-randomly, or pick one CliRunner test followed by tests/units/utils/test_migrations.py).
Expected
Each test starts with the same environment. A test that invokes the CLI in-process does not change os.environ or the global logging configuration for later tests.
Fix direction
- Add an autouse fixture in
tests/units/conftest.pythat removesREFLEX_MANAGED_LOGGINGbefore each test (monkeypatch.delenv(log._MANAGED_ENV_VAR, raising=False), fromreflex_base.utils.log) so monkeypatch restores it afterwards, and resets the logging sinks the same way the existing tests intests/units/reflex_base/utils/test_log.pydo. - Tests that need managed logging already set it with
monkeypatch.setenv(e.g.tests/units/reflex_cli/v2/conftest.py); they keep working. - Non-goal: do not change
cli()itself; setting the variable there is how worker subprocesses inherit managed logging.
- Lenguaje dominante
- Python
- Estrellas
- 29k
- Forks
- 1.8k
- Merge medio
- 2 d 22 h
- PR fusionados (30 d)
- 154
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de reflex-dev/reflex
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
reflex-dev/reflex#7915 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Websocket origin rejection warning does not mention a trusted X-Forwarded-Proto when that is the causePosiblemente ocupada @MaiAditya la tomó hace 4 días. Abiertobug release-train
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
reflex-dev/reflex#7857 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Kept env.py failure: the "move it aside" hint is dropped and a full traceback is logged when alembic.ini uses a relative script_locationPosiblemente ocupada @MaiAditya la tomó hace 4 días. Abiertobug release-train
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
reflex-dev/reflex#7856 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
A dev run stopped before its backend loads leaves .web/nocompile, so the next run or export skips the compilePosiblemente ocupada @YusefSyed la tomó hace 6 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
reflex-dev/reflex#7825 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
PropsBase nested serialization applies parent include/exclude filters to child fieldsPosiblemente ocupada @harsh21234i la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
reflex-dev/reflex#7787 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de reflex-dev/reflex
Issues similares
-
Feature Request
Dificultad 1/5 1-3 horas Aptitud para principiantes 68/100
spotDL/spotify-downloader#2839 ·
Los mantenedores suelen responder en 1 día
-
Missing license fileAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
-
ops/setup.py writes ops/hub.json non-atomically (the torn-write class of #219, in the installer)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
mattabate/life-distributable#230 ·
Los mantenedores suelen responder en 1 día
-
enhancement triage:not-checked
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
inventree/InvenTree#13318 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
google/secops-wrapper#229 ·