diff --git a/news/12508.trivial.rst b/news/12508.trivial.rst new file mode 100644 index 00000000000..fa2cc081f19 --- /dev/null +++ b/news/12508.trivial.rst @@ -0,0 +1,3 @@ +Fix a few test cases to correctly test timestamps generated in log messages +when run in the southern hemisphere in a geography that uses daylight savings +and on a ``timet`` that would fall within daylight savings. diff --git a/tests/unit/test_base_command.py b/tests/unit/test_base_command.py index 44dae384a75..1ff20e21094 100644 --- a/tests/unit/test_base_command.py +++ b/tests/unit/test_base_command.py @@ -17,10 +17,13 @@ @pytest.fixture def fixed_time() -> Iterator[None]: - with patch("time.time", lambda: 1547704837.040001 + time.timezone): + with patch("time.time", lambda: 1547704837.040001): yield +logging.Formatter.converter = time.gmtime + + class FakeCommand(Command): _name = "fake" diff --git a/tests/unit/test_logging.py b/tests/unit/test_logging.py index 9d507d74277..cfe502216ec 100644 --- a/tests/unit/test_logging.py +++ b/tests/unit/test_logging.py @@ -15,6 +15,8 @@ logger = logging.getLogger(__name__) +logging.Formatter.converter = time.gmtime + class TestIndentingFormatter: """Test ``pip._internal.utils.logging.IndentingFormatter``.""" @@ -23,7 +25,7 @@ def make_record(self, msg: str, level_name: str) -> logging.LogRecord: level_number = getattr(logging, level_name) attrs = { "msg": msg, - "created": 1547704837.040001 + time.timezone, + "created": 1547704837.040001, "msecs": 40, "levelname": level_name, "levelno": level_number,