question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some unit tests are sensitive to Timezone of host machine

See original GitHub issue

Description

Running the pip unit tests on Windows in (UTC-5:00) Eastern (US & Canada):

  1. nox -s test-3.7 – -m unit --verbose --numprocesses auto --showlocals

I get a handful of FAILEDs, however if I change the hosts timezone to UTC I get 5 less FAILEDs, specifically this set of tests:

FAILED tests/unit/test_base_command.py::test_log_file_command_error - assert False
FAILED tests/unit/test_base_command.py::test_log_command_error - assert False
FAILED tests/unit/test_base_command.py::test_log_command_success - AssertionError: assert '2019-01-17T01:00:37,040 fake' == '2019-01-17T06:00:37,040 fake'
FAILED tests/unit/test_logging.py::TestIndentingFormatter::test_format_with_timestamp[INFO-2019-01-17T06:00:37,040 hello\n2019-01-17T06:00:37,040 world] - As...
FAILED tests/unit/test_logging.py::TestIndentingFormatter::test_format_with_timestamp[WARNING-2019-01-17T06:00:37,040 WARNING: hello\n2019-01-17T06:00:37,040 world]

Expected behavior

Shouldn’t need to change timezone to run pip tests locally?

pip version

22

Python version

3.7.9

OS

Windows 10

How to Reproduce

Above

Output

No response

Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
notatallshawcommented, Jan 21, 2022

Unless someone else is very motivated to fix these I’m happy to try and make a PR this weekend, give me a chance to learn a bit more about tests. I’ll update back here with my progress if I run in to an issue I can’t fix.

0reactions
uranusjrcommented, Jan 31, 2022
Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> now = datetime.datetime.now()
>>> print(now)
2022-01-31 14:37:10.435059
>>> local_now = now.astimezone()
>>> print(local_now)
2022-01-31 14:37:10.435059+08:00
>>> local_tz = local_now.tzinfo
>>> print(local_tz)
Taipei Standard Time
>>> local_tzname = local_tz.tzname(local_now)
>>> print(local_tzname)
Taipei Standard Time
>>>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Override Java System.currentTimeMillis for testing time ...
True time, different time zone. You can control which time zone is assigned by the Clock implementation. This might be useful in some...
Read more >
A Simple Guide for Testing DateTime - Mudbath
Here are some top tips for your timezone unit tests! ... Do not create datetimes relative to the machine's timezone, but expect datetimes ......
Read more >
Abstracting System Time in ASP.NET Applications - Simple Talk
Right--UtcNow is absolute time; Now is not and depends on the timezone configured on the server. But when the application is sensitive to...
Read more >
Timekeeping in VMware Virtual Machines
The virtual machine checks for pending virtual timer interrupts only at certain points, such as when the underlying hardware receives a physical timer...
Read more >
Testing best practices - GitLab Docs
GitLab development guidelines - testing best practices. ... Fast unit tests ... Any test that exercises or verifies something time-sensitive should make use ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found