coveralls: 
[![Coverage Status](https://coveralls.io/builds/8538937/badge)](https://coveralls.io/builds/8538937)

Coverage decreased (-0.5%) to 95.726% when pulling **88b1f06d959015d916d116e7687c8e26ea4b2a57 on pelme:ignore-deprecation-warnings** into **11d9ead16a55fd31fb545a663a2b758049b4b40d on spulec:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/8539163/badge)](https://coveralls.io/builds/8539163)

Coverage decreased (-0.5%) to 95.726% when pulling **35b2fc1c3d7db2074cbdcf079413b2a8b0a5b100 on pelme:ignore-deprecation-warnings** into **11d9ead16a55fd31fb545a663a2b758049b4b40d on spulec:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/8539163/badge)](https://coveralls.io/builds/8539163)

Coverage decreased (-0.5%) to 95.726% when pulling **35b2fc1c3d7db2074cbdcf079413b2a8b0a5b100 on pelme:ignore-deprecation-warnings** into **11d9ead16a55fd31fb545a663a2b758049b4b40d on spulec:master**.

diff --git a/freezegun/api.py b/freezegun/api.py
index 9f63fe9..4502e32 100644
--- a/freezegun/api.py
+++ b/freezegun/api.py
@@ -6,6 +6,7 @@ import time
 import calendar
 import unittest
 import platform
+import warnings
 
 from dateutil import parser
 from dateutil.tz import tzlocal
@@ -390,25 +391,28 @@ class _freeze_time(object):
         # Save the current loaded modules
         self.modules_at_start = set(sys.modules.keys())
 
-        for mod_name, module in list(sys.modules.items()):
-            if mod_name is None or module is None:
-                continue
-            elif mod_name.startswith(self.ignore):
-                continue
-            elif (not hasattr(module, "__name__") or module.__name__ in ('datetime', 'time')):
-                continue
-            for module_attribute in dir(module):
-                if module_attribute in real_names:
+        with warnings.catch_warnings():
+            warnings.filterwarnings('ignore')
+
+            for mod_name, module in list(sys.modules.items()):
+                if mod_name is None or module is None:
                     continue
-                try:
-                    attribute_value = getattr(module, module_attribute)
-                except (ImportError, AttributeError, TypeError):
-                    # For certain libraries, this can result in ImportError(_winreg) or AttributeError (celery)
+                elif mod_name.startswith(self.ignore):
                     continue
-                fake = fakes.get(id(attribute_value))
-                if fake:
-                    setattr(module, module_attribute, fake)
-                    add_change((module, module_attribute, attribute_value))
+                elif (not hasattr(module, "__name__") or module.__name__ in ('datetime', 'time')):
+                    continue
+                for module_attribute in dir(module):
+                    if module_attribute in real_names:
+                        continue
+                    try:
+                        attribute_value = getattr(module, module_attribute)
+                    except (ImportError, AttributeError, TypeError):
+                        # For certain libraries, this can result in ImportError(_winreg) or AttributeError (celery)
+                        continue
+                    fake = fakes.get(id(attribute_value))
+                    if fake:
+                        setattr(module, module_attribute, fake)
+                        add_change((module, module_attribute, attribute_value))
 
         datetime.datetime.times_to_freeze.append(time_to_freeze)
         datetime.datetime.tz_offsets.append(self.tz_offset)
@@ -436,26 +440,29 @@ class _freeze_time(object):
             # Restore modules loaded after start()
             modules_to_restore = set(sys.modules.keys()) - self.modules_at_start
             self.modules_at_start = set()
-            for mod_name in modules_to_restore:
-                module = sys.modules.get(mod_name, None)
-                if mod_name is None or module is None:
-                    continue
-                elif mod_name.startswith(self.ignore):
-                    continue
-                elif (not hasattr(module, "__name__") or module.__name__ in ('datetime', 'time')):
-                    continue
-                for module_attribute in dir(module):
-                    if module_attribute in self.fake_names:
+            with warnings.catch_warnings():
+                warnings.simplefilter('ignore')
+                for mod_name in modules_to_restore:
+                    module = sys.modules.get(mod_name, None)
+                    if mod_name is None or module is None:
                         continue
-                    try:
-                        attribute_value = getattr(module, module_attribute)
-                    except (ImportError, AttributeError, TypeError):
-                        # For certain libraries, this can result in ImportError(_winreg) or AttributeError (celery)
+                    elif mod_name.startswith(self.ignore):
                         continue
-
-                    real = self.reals.get(id(attribute_value))
-                    if real:
-                        setattr(module, module_attribute, real)
+                    elif (not hasattr(module, "__name__") or module.__name__ in ('datetime', 'time')):
+                        continue
+                    for module_attribute in dir(module):
+
+                        if module_attribute in self.fake_names:
+                            continue
+                        try:
+                            attribute_value = getattr(module, module_attribute)
+                        except (ImportError, AttributeError, TypeError):
+                            # For certain libraries, this can result in ImportError(_winreg) or AttributeError (celery)
+                            continue
+
+                        real = self.reals.get(id(attribute_value))
+                        if real:
+                            setattr(module, module_attribute, real)
 
         time.time = time.time.previous_time_function
         time.gmtime = time.gmtime.previous_gmtime_function

Freezetime's access to every imported module's attribute triggers celery's deprecation warnings
Since https://github.com/spulec/freezegun/commit/70518d630c71a37d3c651dee7b73d347b5d75405 freezegun has been fetching every attribute from every imported module to check if it matches one of the patchable date. However, the celery package imports a number of modules that throw deprecation warnings on their access.  Celery slightly complicates the tracking down of this issue because it implements some LazyModule functionality so the deprecation warnings show when first accessed. Normally this prevents the warnings from showing to developer unless they intended to use a deprecated module, but since freezegun touches ever attribute on every module, the warning is always thrown.

diff --git a/tests/test_warnings.py b/tests/test_warnings.py
new file mode 100644
index 0000000..7747081
--- /dev/null
+++ b/tests/test_warnings.py
@@ -0,0 +1,84 @@
+import contextlib
+import datetime
+import sys
+import types
+import warnings
+
+from freezegun import freeze_time
+
+
+class ModuleWithWarning(object):
+    """
+    A module that triggers warnings on attribute access.
+
+    This does not happen with regular modules, there has to be a bit of lazy
+    module magic going on in order for this to happen.
+
+    Examples of modules that uses this pattern in real projects can be found at:
+
+    py.code - the compiler package import causes a warning to be emitted:
+    https://github.com/pytest-dev/py/blob/67987e26aadddbbe7d1ec76c16ea9be346ae9811/py/__init__.py
+    https://github.com/pytest-dev/py/blob/67987e26aadddbbe7d1ec76c16ea9be346ae9811/py/_code/_assertionold.py#L3
+
+    celery.task - the sets module is listed in __all__ in celery.task and freeze_time accesses it:
+    https://github.com/celery/celery/blob/46c92025cdec07a4a30ad44901cf66cb27346638/celery/task/__init__.py
+    https://github.com/celery/celery/blob/46c92025cdec07a4a30ad44901cf66cb27346638/celery/task/sets.py
+    """
+    __name__ = 'module_with_warning'
+    __dict__ = {}
+    warning_triggered = False
+    counter = 0
+
+    @property
+    def attribute_that_emits_a_warning(self):
+        # Use unique warning messages to avoid messages being only reported once
+        self.__class__.counter += 1
+        warnings.warn('this is test warning #{counter}'.format(counter=self.__class__.counter))
+        self.warning_triggered = True
+
+
+@contextlib.contextmanager
+def assert_module_with_emitted_warning():
+    """Install a module that triggers warnings into sys.modules and ensure the
+    warning was triggered in the with-block.  """
+    module = sys.modules['module_with_warning'] = ModuleWithWarning()
+
+    try:
+        yield
+    finally:
+        del sys.modules['module_with_warning']
+
+    assert module.warning_triggered
+
+
+@contextlib.contextmanager
+def assert_no_warnings():
+    """A context manager that makes sure no warnings was emitted."""
+    with warnings.catch_warnings(record=True) as caught_warnings:
+        warnings.filterwarnings('always')
+        yield
+        assert not caught_warnings
+
+
+def test_ignore_warnings_in_start():
+    """Make sure that modules being introspected in start() does not emit warnings."""
+    with assert_module_with_emitted_warning():
+        freezer = freeze_time(datetime.datetime(2016, 10, 27, 9, 56))
+
+        try:
+            with assert_no_warnings():
+                freezer.start()
+
+        finally:
+            freezer.stop()
+
+
+def test_ignore_warnings_in_stop():
+    """Make sure that modules that was loaded after start() does not trigger
+    warnings in stop()"""
+    freezer = freeze_time(datetime.datetime(2016, 10, 27, 9, 56))
+    freezer.start()
+
+    with assert_module_with_emitted_warning():
+        with assert_no_warnings():
+            freezer.stop()

pip install -e .
parse_log_pytest
requirements.txt
nose pytest
apt-get update apt-get install -y gcc
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi==2025.1.31
charset-normalizer==3.4.1
coverage==3.7.1
coveralls==1.11.1
docopt==0.6.2
exceptiongroup==1.2.2
-e git+https://github.com/spulec/freezegun.git@11d9ead16a55fd31fb545a663a2b758049b4b40d#egg=freezegun
idna==3.10
iniconfig==2.1.0
mock==5.2.0
nose==1.3.7
packaging==24.2
pluggy==1.5.0
pytest==8.3.5
python-dateutil==2.9.0.post0
requests==2.32.3
six==1.17.0
tomli==2.2.1
urllib3==2.3.0

name: freezegun
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - coverage==3.7.1
      - coveralls==1.11.1
      - docopt==0.6.2
      - exceptiongroup==1.2.2
      - idna==3.10
      - iniconfig==2.1.0
      - mock==5.2.0
      - nose==1.3.7
      - packaging==24.2
      - pluggy==1.5.0
      - pytest==8.3.5
      - python-dateutil==2.9.0.post0
      - requests==2.32.3
      - six==1.17.0
      - tomli==2.2.1
      - urllib3==2.3.0
prefix: /opt/conda/envs/freezegun

tests/test_warnings.py::test_ignore_warnings_in_start tests/test_warnings.py::test_ignore_warnings_in_stop
freezegun/api.py
freezegun/api.py