diff --git a/pendulum/tz/local_timezone.py b/pendulum/tz/local_timezone.py index 08a6e4fa..09747aee 100644 --- a/pendulum/tz/local_timezone.py +++ b/pendulum/tz/local_timezone.py @@ -248,7 +248,11 @@ def _tz_from_env(tzenv): # type: (str) -> Timezone # TZ specifies a file if os.path.exists(tzenv): - return TimezoneFile(tzenv) + try: + return TimezoneFile(tzenv) + except FileNotFoundError: + # if cannot load from timezone file, assume path existing is coincidence + pass # TZ specifies a zoneinfo zone. try: diff --git a/tests/tz/test_local_timezone.py b/tests/tz/test_local_timezone.py index fdf1cc2f..478f4a36 100644 --- a/tests/tz/test_local_timezone.py +++ b/tests/tz/test_local_timezone.py @@ -7,6 +7,16 @@ from pendulum.tz.local_timezone import _get_windows_timezone +@pytest.mark.skipif( + sys.platform == "win32", reason="Test only available for UNIX systems" +) +def test_unix_environment_variable(monkeypatch): + # localtime can be set on unix with TZ environment variable + monkeypatch.setenv("TZ", "UTC") + tz = _get_unix_timezone() + assert tz.name == "UTC" + + @pytest.mark.skipif( sys.platform == "win32", reason="Test only available for UNIX systems" )