MCPcopy Index your code
hub / github.com/tortoise/tortoise-orm / test_datetime_timezone

Function test_datetime_timezone

tests/fields/test_time.py:223–236  ·  view source on GitHub ↗

Test timezone handling with USE_TZ enabled.

(db, tz_env)

Source from the content-addressed store, hash-verified

221
222@pytest.mark.asyncio
223async def test_datetime_timezone(db, tz_env):
224 """Test timezone handling with USE_TZ enabled."""
225 model = testmodels.DatetimeFields
226 tz = "Asia/Shanghai"
227 os.environ["TIMEZONE"] = tz
228 os.environ["USE_TZ"] = "True"
229 timezone._reset_timezone_cache()
230
231 now = datetime.now(parse_timezone(tz))
232 obj = await model.create(datetime=now)
233 assert obj.datetime.tzinfo.zone == tz
234 obj_get = await model.get(pk=obj.pk)
235 assert obj.datetime.tzinfo.zone == tz
236 assert obj_get.datetime == now
237
238
239def test_timezone_now_returns_naive_when_use_tz_false(tz_env):

Callers

nothing calls this directly

Calls 3

parse_timezoneFunction · 0.90
createMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…