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.
()
| 44 | |
| 45 | @pytest.fixture |
| 46 | def 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 | |
| 66 | def test_datetime_both_auto_bad(db): |
nothing calls this directly
no test coverage detected
searching dependent graphs…