MCPcopy Create free account
hub / github.com/tortoise/tortoise-orm / tz_env

Function tz_env

tests/fields/test_time.py:46–63  ·  view source on GitHub ↗

Fixture that restores USE_TZ and TIMEZONE env vars after test. Tests that mutate os.environ["USE_TZ"] or os.environ["TIMEZONE"] should use this fixture to guarantee cleanup even if the test fails.

()

Source from the content-addressed store, hash-verified

44
45@pytest.fixture
46def tz_env():
47 """Fixture that restores USE_TZ and TIMEZONE env vars after test.
48
49 Tests that mutate os.environ["USE_TZ"] or os.environ["TIMEZONE"]
50 should use this fixture to guarantee cleanup even if the test fails.
51 """
52 old_use_tz = os.environ.get("USE_TZ")
53 old_tz = os.environ.get("TIMEZONE")
54 yield
55 if old_use_tz is not None:
56 os.environ["USE_TZ"] = old_use_tz
57 else:
58 os.environ.pop("USE_TZ", None)
59 if old_tz is not None:
60 os.environ["TIMEZONE"] = old_tz
61 else:
62 os.environ.pop("TIMEZONE", None)
63 timezone._reset_timezone_cache()
64
65
66def test_datetime_both_auto_bad(db):

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…