Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions mcoplib/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@

def _is_profiler_enabled() -> bool:
"""
Env switch: PROFILER_ENABLED==0 -> disabled, else enabled.
Env switch: PROFILER_ENABLED=false/0/off/no -> disabled, else enabled.
"""
v = os.getenv("PROFILER_ENABLED", "1")
try:
return not (str(v).strip() == "0")
except Exception:
return True
return v.strip().lower() not in {"0", "false", "off", "no"}


def _timestamp() -> str:
Expand Down
12 changes: 12 additions & 0 deletions unit_test/test_profiler_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from mcoplib.profiler import _is_profiler_enabled


def test_profiler_disabled_by_common_false_values(monkeypatch):
for value in ("0", "false", "False", "off", "NO"):
monkeypatch.setenv("PROFILER_ENABLED", value)
assert not _is_profiler_enabled()


def test_profiler_enabled_by_default(monkeypatch):
monkeypatch.delenv("PROFILER_ENABLED", raising=False)
assert _is_profiler_enabled()