Unit tests: invoking the reflex CLI in-process leaves REFLEX_MANAGED_LOGGING=true in os.environ for every later test
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
从 tests/units/conftest.py 中的 autouse fixture 和 tests/units/reflex_base/utils/test_log.py 中的 logging 重置示例入手。检查 tests/units/reflex_cli/v2/conftest.py 如何启用 managed logging,以便这些测试保留其设置。完成标准是每个测试开始时都没有残留的 REFLEX_MANAGED_LOGGING 或 logging sink 状态;运行受影响的单元测试,包括先调用 CLI 再运行迁移测试。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Python
- 星标
- 29k
- 派生
- 1.8k
- 平均合并
- 2 天 22 小时
- 30 天内合并 PR
- 154
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
reflex-dev/reflex 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
reflex-dev/reflex#7915 · 1 条评论 ·
维护者通常 1 天内回复
-
Websocket origin rejection warning does not mention a trusted X-Forwarded-Proto when that is the cause可能已有人在做 @MaiAditya 于 4 天前认领。 未关闭bug release-train
难度 2/5 1-3 小时 新手友好度 78/100
reflex-dev/reflex#7857 · 1 条评论 ·
维护者通常 1 天内回复
-
Kept env.py failure: the "move it aside" hint is dropped and a full traceback is logged when alembic.ini uses a relative script_location可能已有人在做 @MaiAditya 于 4 天前认领。 未关闭bug release-train
难度 2/5 1-3 小时 新手友好度 78/100
reflex-dev/reflex#7856 · 1 条评论 ·
维护者通常 1 天内回复
-
A dev run stopped before its backend loads leaves .web/nocompile, so the next run or export skips the compile可能已有人在做 @YusefSyed 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
reflex-dev/reflex#7825 · 1 条评论 ·
维护者通常 1 天内回复
-
PropsBase nested serialization applies parent include/exclude filters to child fields可能已有人在做 @harsh21234i 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
reflex-dev/reflex#7787 · 1 条评论 ·
维护者通常 1 天内回复
查看 reflex-dev/reflex 的全部 Issue
相似的 Issue
-
Feature Request
难度 1/5 1-3 小时 新手友好度 68/100
spotDL/spotify-downloader#2839 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
-
ops/setup.py writes ops/hub.json non-atomically (the torn-write class of #219, in the installer)未关闭
难度 2/5 1-3 小时 新手友好度 79/100
mattabate/life-distributable#230 ·
维护者通常 1 天内回复
-
enhancement triage:not-checked
难度 2/5 1-3 小时 新手友好度 66/100
inventree/InvenTree#13318 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
google/secops-wrapper#229 ·