Repository: spulec/freezegun

Issue:
version 0.3.13 break previous behavior with webtest
Hello, i'm using freezegun with webtest to check a cookie auth mecanism. It's working perfectly fine until freezegun 0.3.13.

Sample of broken test (see also https://travis-ci.org/tracim/tracim/jobs/636791961?utm_medium=notification&utm_source=github_status): 
```
    def test_api__test_cookie_auth_token__ok__revocation_case(self, web_testapp):
        with freeze_time("1999-12-31 23:59:59"):
            params = {"email": "admin@admin.admin", "password": "admin@admin.admin"}
            res = web_testapp.post_json("/api/v2/auth/login", params=params, status=200)
            assert "Set-Cookie" in res.headers
>           assert "session_key" in web_testapp.cookies
E           AssertionError: assert 'session_key' in {}
E            +  where {} = <webtest.app.TestApp object at 0x7fd9ec7c1f28>.cookies
```

Do you have any idea why the new version can break this test ?

Discussion:

Patch:
diff --git a/freezegun/api.py b/freezegun/api.py
index 13484ca..6096896 100644
--- a/freezegun/api.py
+++ b/freezegun/api.py
@@ -26,10 +26,9 @@ real_time = time.time
 real_localtime = time.localtime
 real_gmtime = time.gmtime
 real_strftime = time.strftime
-real_timegm = calendar.timegm
 real_date = datetime.date
 real_datetime = datetime.datetime
-real_date_objects = [real_time, real_localtime, real_gmtime, real_strftime, real_timegm, real_date, real_datetime]
+real_date_objects = [real_time, real_localtime, real_gmtime, real_strftime, real_date, real_datetime]
 
 if _TIME_NS_PRESENT:
     real_time_ns = time.time_ns
@@ -183,7 +182,7 @@ def fake_time():
     if _should_use_real_time():
         return real_time()
     current_time = get_current_time()
-    return real_timegm(current_time.timetuple()) + current_time.microsecond / 1000000.0
+    return calendar.timegm(current_time.timetuple()) + current_time.microsecond / 1000000.0
 
 if _TIME_NS_PRESENT:
     def fake_time_ns():
@@ -219,14 +218,6 @@ def fake_strftime(format, time_to_format=None):
     else:
         return real_strftime(format, time_to_format)
 
-
-def fake_timegm(struct_time):
-    if _should_use_real_time():
-        return real_timegm(struct_time)
-    else:
-        return real_timegm(get_current_time().timetuple())
-
-
 if real_clock is not None:
     def fake_clock():
         if _should_use_real_time():
@@ -598,8 +589,6 @@ class _freeze_time(object):
             return freeze_factory
 
         # Change the modules
-        calendar.timegm = fake_timegm
-
         datetime.datetime = FakeDatetime
         datetime.date = FakeDate
 
@@ -623,7 +612,6 @@ class _freeze_time(object):
             ('real_localtime', real_localtime, fake_localtime),
             ('real_strftime', real_strftime, fake_strftime),
             ('real_time', real_time, fake_time),
-            ('real_timegm', real_timegm, fake_timegm),
         ]
 
         if _TIME_NS_PRESENT:
@@ -670,7 +658,6 @@ class _freeze_time(object):
         tz_offsets.pop()
 
         if not freeze_factories:
-            calendar.timegm = real_timegm
             datetime.datetime = real_datetime
             datetime.date = real_date
             copyreg.dispatch_table.pop(real_datetime)


Test patch:
diff --git a/tests/another_module.py b/tests/another_module.py
index 936bd7d..637c889 100644
--- a/tests/another_module.py
+++ b/tests/another_module.py
@@ -1,4 +1,3 @@
-from calendar import timegm
 from datetime import date, datetime
 from time import time, localtime, gmtime, strftime
 
@@ -9,7 +8,6 @@ from freezegun.api import (
     fake_localtime,
     fake_gmtime,
     fake_strftime,
-    fake_timegm,
 )
 
 
@@ -39,10 +37,6 @@ def get_strftime():
     return strftime
 
 
-def get_timegm():
-    return timegm
-
-
 # Fakes
 
 def get_fake_datetime():
@@ -67,7 +61,3 @@ def get_fake_gmtime():
 
 def get_fake_strftime():
     return fake_strftime
-
-
-def get_fake_timegm():
-    return fake_timegm
diff --git a/tests/test_class_import.py b/tests/test_class_import.py
index 36a6178..1c98215 100644
--- a/tests/test_class_import.py
+++ b/tests/test_class_import.py
@@ -1,5 +1,3 @@
-import calendar
-import datetime
 import time
 import sys
 from .fake_module import (
@@ -19,8 +17,8 @@ from freezegun.api import (
     fake_localtime,
     fake_gmtime,
     fake_strftime,
-    fake_timegm,
 )
+import datetime
 
 
 @freeze_time("2012-01-14")
@@ -150,8 +148,6 @@ def test_import_after_start():
         assert another_module.get_gmtime() is fake_gmtime
         assert another_module.get_strftime() is time.strftime
         assert another_module.get_strftime() is fake_strftime
-        assert another_module.get_timegm() is calendar.timegm
-        assert another_module.get_timegm() is fake_timegm
 
         # Fakes
         assert another_module.get_fake_datetime() is FakeDatetime
@@ -160,7 +156,6 @@ def test_import_after_start():
         assert another_module.get_fake_localtime() is fake_localtime
         assert another_module.get_fake_gmtime() is fake_gmtime
         assert another_module.get_fake_strftime() is fake_strftime
-        assert another_module.get_fake_timegm() is fake_timegm
 
     # Reals
     assert another_module.get_datetime() is datetime.datetime
@@ -175,8 +170,6 @@ def test_import_after_start():
     assert not another_module.get_gmtime() is fake_gmtime
     assert another_module.get_strftime() is time.strftime
     assert not another_module.get_strftime() is fake_strftime
-    assert another_module.get_timegm() is calendar.timegm
-    assert not another_module.get_timegm() is fake_timegm
 
     # Fakes
     assert another_module.get_fake_datetime() is FakeDatetime
@@ -185,7 +178,6 @@ def test_import_after_start():
     assert another_module.get_fake_localtime() is fake_localtime
     assert another_module.get_fake_gmtime() is fake_gmtime
     assert another_module.get_fake_strftime() is fake_strftime
-    assert another_module.get_fake_timegm() is fake_timegm
 
 
 def test_none_as_initial():
diff --git a/tests/test_datetimes.py b/tests/test_datetimes.py
index 4689dcf..9bafb49 100644
--- a/tests/test_datetimes.py
+++ b/tests/test_datetimes.py
@@ -211,13 +211,6 @@ def test_time_gmtime():
         assert time_struct.tm_isdst == -1
 
 
-def test_calendar_timegm():
-    time_struct = time.gmtime()
-    assert calendar.timegm(time_struct) != 1326511294
-    with freeze_time('2012-01-14 03:21:34'):
-        assert calendar.timegm(time_struct) == 1326511294
-
-
 @pytest.mark.skipif(not HAS_CLOCK,
                     reason="time.clock was removed in Python 3.8")
 def test_time_clock():
@@ -652,7 +645,8 @@ def test_should_use_real_time():
     from freezegun import api
     api.call_stack_inspection_limit = 100  # just to increase coverage
 
-    current_time = time.gmtime()
+    timestamp_to_convert = 1579602312
+    time_tuple = time.gmtime(timestamp_to_convert)
 
     with freeze_time(frozen):
         assert time.time() == expected_frozen
@@ -663,7 +657,8 @@ def test_should_use_real_time():
         if HAS_TIME_NS:
             assert time.time_ns() == expected_frozen * 1e9
 
-        assert calendar.timegm(current_time) == expected_frozen
+        assert calendar.timegm(time.gmtime()) == expected_frozen
+        assert calendar.timegm(time_tuple) == timestamp_to_convert
 
     with freeze_time(frozen, ignore=['_pytest', 'nose']):
         assert time.time() != expected_frozen
@@ -674,7 +669,8 @@ def test_should_use_real_time():
         if HAS_TIME_NS:
             assert time.time_ns() != expected_frozen * 1e9
 
-        assert calendar.timegm(current_time) != expected_frozen
+        assert calendar.timegm(time.gmtime()) != expected_frozen
+        assert calendar.timegm(time_tuple) == timestamp_to_convert
 
 
 @pytest.mark.skipif(not HAS_TIME_NS,