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

Test fails, if TZ=UTC is not set #320

Open
dvzrv opened this issue Aug 4, 2018 · 4 comments
Open

Test fails, if TZ=UTC is not set #320

dvzrv opened this issue Aug 4, 2018 · 4 comments
Labels

Comments

@dvzrv
Copy link

dvzrv commented Aug 4, 2018

Currently the following test fails, if not prefixed by an export TZ=UTC:

============================= test session starts ==============================
platform linux -- Python 3.7.0, pytest-3.6.4, py-1.5.4, pluggy-0.7.1
rootdir: /build/todoman/src/todoman-3.4.0, inifile: setup.cfg
plugins: hypothesis-3.66.24
collected 176 items

tests/test_backend.py .........                                          [  5%]
tests/test_cli.py .............x..........F...........................s. [ 35%]
...........                                                              [ 42%]
tests/test_config.py .......xx......                                     [ 50%]
tests/test_filtering.py .........                                        [ 55%]
tests/test_formatter.py ...............                                  [ 64%]
tests/test_main.py .                                                     [ 64%]
tests/test_model.py ............ss..ss................                   [ 84%]
tests/test_porcelain.py ........                                         [ 88%]
tests/test_ui.py ...........                                             [ 94%]
tests/test_widgets.py .........                                          [100%]

=================================== FAILURES ===================================
______________________________ test_default_due2 _______________________________

tmpdir = local('/tmp/pytest-of-builduser/pytest-0/test_default_due20')
runner = <conftest.runner.<locals>.SleepyCliRunner object at 0x6fac5c3d2d30>
create = <function create.<locals>.inner at 0x6fac5c466d08>
todos = {'aaa': <todoman.model.Todo object at 0x6fac5c3be438>, 'bbb': <todoman.model.Todo object at 0x6fac5c3be198>, 'ccc': <todoman.model.Todo object at 0x6fac5c3be400>}

    @pyicu_sensitive
    @freeze_time(datetime.datetime.now())
    def test_default_due2(tmpdir, runner, create, todos):
        cfg = tmpdir.join('config')
        cfg.write('default_due = 24\n', 'a')
    
        r = runner.invoke(cli, ['new', '-ldefault', '-dtomorrow', 'aaa'])
        assert not r.exception
        r = runner.invoke(cli, ['new', '-ldefault', 'bbb'])
        assert not r.exception
        r = runner.invoke(cli, ['new', '-ldefault', '-d', 'one hour', 'ccc'])
        assert not r.exception
    
        todos = {t.summary: t for t in todos(status='ANY')}
        assert todos['aaa'].due.date() == todos['bbb'].due.date()
>       assert todos['ccc'].due == todos['bbb'].due - datetime.timedelta(hours=23)
E       AssertionError: assert FakeDatetime(2018, 8, 4, 19, 32, 48, tzinfo=tzlocal()) == (FakeDatetime(2018, 8, 5, 19, 32, 48, tzinfo=tzlocal()) - datetime.timedelta(seconds=82800))
E        +  where FakeDatetime(2018, 8, 4, 19, 32, 48, tzinfo=tzlocal()) = <todoman.model.Todo object at 0x6fac5c3be400>.due
E        +  and   FakeDatetime(2018, 8, 5, 19, 32, 48, tzinfo=tzlocal()) = <todoman.model.Todo object at 0x6fac5c3be198>.due
E        +  and   datetime.timedelta(seconds=82800) = <class 'datetime.timedelta'>(hours=23)
E        +    where <class 'datetime.timedelta'> = datetime.timedelta

tests/test_cli.py:302: AssertionError
========= 1 failed, 167 passed, 5 skipped, 3 xfailed in 10.30 seconds ==========

Tests should not depend on a specific timezone to be set.

@WhyNotHugo WhyNotHugo added the bug label Aug 4, 2018
@WhyNotHugo
Copy link
Member

WhyNotHugo commented Aug 5, 2018

I just checked the AUR package's history to find out a bit more about this. (link)

This is actually due to a bug in freezegun, and only occurs for some timezones. The AUR package sets TZ=UTC to work around it.

I'll have to dig a bit more to try and find out what the issue with freezegun was though, cause I didn't link to an actual ticket. :(

@WhyNotHugo
Copy link
Member

Actually, it doesn't look like an issue with freezegun. 😛

For this test, we spoof the current time, but depending on your timezone and the time, this might mean it's already "tomorrow" UTC.

I'll have to think about this a bit more, but it can probably be fixed on our end. I'm actually tempted to add TZ=UTC to tox.ini though, since this doesn't really reflect any breakage on todoman itself.

@dvzrv
Copy link
Author

dvzrv commented Nov 21, 2018

Hm, with todoman 3.5.0 I'm not experiencing this issue... but maybe it's flaky behavior?

@WhyNotHugo
Copy link
Member

It depends on your actual timezone.

For some tests we use things like "21hs UTC". If this is "today" in your local TZ, test work, if this is "tomorrow" it fails.

That's why we override the TZ for tests; so as to be sure that the conditions are know ahead of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants