Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In test cases, use gmtime to avoid timezone & daylight savings issues #12508

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions news/12508.trivial.rst
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion tests/unit/test_base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in a fixture instead? Modifying the global state in test seems wrong to me.



class FakeCommand(Command):
_name = "fake"

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

logger = logging.getLogger(__name__)

logging.Formatter.converter = time.gmtime


class TestIndentingFormatter:
"""Test ``pip._internal.utils.logging.IndentingFormatter``."""
Expand All @@ -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,
Expand Down