diff --git a/pandas/_testing/contexts.py b/pandas/_testing/contexts.py index 91b5d2a981bef..4ca67d6fc082d 100644 --- a/pandas/_testing/contexts.py +++ b/pandas/_testing/contexts.py @@ -73,14 +73,15 @@ def set_timezone(tz: str) -> Generator[None, None, None]: import time def setTZ(tz) -> None: - if tz is None: - try: - del os.environ["TZ"] - except KeyError: - pass - else: - os.environ["TZ"] = tz - time.tzset() + if hasattr(time, "tzset"): + if tz is None: + try: + del os.environ["TZ"] + except KeyError: + pass + else: + os.environ["TZ"] = tz + time.tzset() orig_tz = os.environ.get("TZ") setTZ(tz) diff --git a/pandas/tests/tslibs/test_parsing.py b/pandas/tests/tslibs/test_parsing.py index 9b64beaf09273..07425af8ed37a 100644 --- a/pandas/tests/tslibs/test_parsing.py +++ b/pandas/tests/tslibs/test_parsing.py @@ -37,10 +37,13 @@ ) def test_parsing_tzlocal_deprecated(): # GH#50791 - msg = ( - r"Parsing 'EST' as tzlocal \(dependent on system timezone\) " - r"is no longer supported\. " - "Pass the 'tz' keyword or call tz_localize after construction instead" + msg = "|".join( + [ + r"Parsing 'EST' as tzlocal \(dependent on system timezone\) " + r"is no longer supported\. " + "Pass the 'tz' keyword or call tz_localize after construction instead", + ".*included an un-recognized timezone", + ] ) dtstr = "Jan 15 2004 03:00 EST"