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 の呼び出しに続けて migration テストを実行するケースを含め、影響を受ける unit test を実行してください。
索引モデルが 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時間
- マージ済み PR(30日)
- 154
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信
-
Missing license fileオープン
難易度 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 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
google/secops-wrapper#229 ·