USStateDept / State-TalentMAP-API

Source Code - https://github.com/USStateDept/State-TalentMAP
Other
12 stars 11 forks source link

CircleCI - FreezeTime Test Failure #191

Closed burgwyn closed 6 years ago

burgwyn commented 6 years ago

There is a regular test failure from CircleCI

=================================== FAILURES ===================================
______________________ test_assignment_estimated_end_date ______________________

authorized_client = <django.test.client.Client object at 0x7f02270aa7f0>
authorized_user = <User: fOkLCSanLsGPhItTbfEkPFdrPAzpSJyLmNsmNVNLXLdAjzFwKqIWkGDSbfOWczCGpQFZiohUzVTjehpkqsawQchhFOdGjJNauxFGxrHDDaMepUmQSoPRbMCBAATdefNIuKECdJivUmaMVBNPQgAajA>
test_assignment_fixture = None

    @freeze_time("1991-02-01")
    @pytest.mark.django_db(transaction=True)
    def test_assignment_estimated_end_date(authorized_client, authorized_user, test_assignment_fixture):
        # Get our required foreign key data
        user = UserProfile.objects.get(user=authorized_user)
        position = Position.objects.first()
        tour_of_duty = TourOfDuty.objects.first()

        # Create an assignment
        assignment = Assignment.objects.create(user=user, position=position, tour_of_duty=tour_of_duty)

        # Assert the dates are currently null
        assert assignment.start_date is None
        assert assignment.estimated_end_date is None

        # Now save a start date
        assignment.start_date = "1991-02-01"
        assignment.save()
        assignment.refresh_from_db()

>       assert assignment.estimated_end_date == datetime.datetime.strptime('1992-02-01', '%Y-%m-%d').date()
E       AssertionError: assert datetime.date(1991, 2, 1) == FakeDate(1992, 2, 1)
E        +  where datetime.date(1991, 2, 1) = <Assignment: (pending) fOkLCSanLsGPhItTbfEkPFdrPAzpSJyLmNsmNVNLXLdAjzFwKqIWkGDSbfOWczCGpQFZiohUzVTjehpkqsawQchhFOdGjJNauxFGxrHDDaMepUmQSoPRbMCBAATdefNIuKECdJivUmaMVBNPQgAajA at [None] None (None)>.estimated_end_date
E        +  and   FakeDate(1992, 2, 1) = <bound method FakeDatetime.date of FakeDatetime(1992, 2, 1, 0, 0)>()
E        +    where <bound method FakeDatetime.date of FakeDatetime(1992, 2, 1, 0, 0)> = FakeDatetime(1992, 2, 1, 0, 0).date
E        +      where FakeDatetime(1992, 2, 1, 0, 0) = <built-in method strptime of FakeDatetimeMeta object at 0x1fd0aa8>('1992-02-01', '%Y-%m-%d')
E        +        where <built-in method strptime of FakeDatetimeMeta object at 0x1fd0aa8> = <class 'freezegun.api.FakeDatetime'>.strptime
E        +          where <class 'freezegun.api.FakeDatetime'> = datetime.datetime

talentmap_api/position/tests/test_assignments.py:38: AssertionError
==================== 1 failed, 156 passed in 68.25 seconds =====================
Exited with code 1
jseppi commented 6 years ago

huh, so using freeze_time didn't actually fix this. I wonder what the underlying issue is.

afrasier commented 6 years ago

Yeah, it's very bizarre. It's not a circleCI thing either, because it (rarely) fails on my machine too

jseppi commented 6 years ago

is it a weird timezone issue where sometimes one of the datetimes is actually the day before or day after because it is UTC and the other one is local time?

afrasier commented 6 years ago

I don't think so, since the date it specifies is the same as the start date (should be +1 year); might be an issue with the relativedelta objects.