File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 33# This product includes software developed at Datadog (https://www.datadoghq.com/).
44# Copyright 2015-Present Datadog, Inc
55import logging
6+ import pytest
7+ import sys
68import unittest
79
810from mock import patch
@@ -48,3 +50,35 @@ def test_function():
4850 mock_debug .assert_called_once ()
4951 else :
5052 mock_debug .assert_not_called ()
53+
54+ def test_slow_imports (monkeypatch ):
55+ # We should lazy load certain modules to avoid slowing down the startup
56+ # time when running in a serverless environment. This test will fail if
57+ # any of those modules are imported during the import of datadogpy.
58+
59+ blocklist = [
60+ 'configparser' ,
61+ 'email.mime.application' ,
62+ 'email.mime.multipart' ,
63+ 'importlib.metadata' ,
64+ 'importlib_metadata' ,
65+ 'logging.handlers' ,
66+ 'multiprocessing' ,
67+ 'urllib.request' ,
68+ ]
69+
70+ class BlockListFinder :
71+ def find_spec (self , fullname , * args ):
72+ for lib in blocklist :
73+ if fullname == lib :
74+ raise ImportError ('module %s was imported!' % fullname )
75+ return None
76+ find_module = find_spec # Python 2
77+
78+ monkeypatch .setattr ('sys.meta_path' , [BlockListFinder ()] + sys .meta_path )
79+
80+ for mod in sys .modules .copy ():
81+ if mod in blocklist or mod .startswith ('datadog' ):
82+ del sys .modules [mod ]
83+
84+ import datadog
You can’t perform that action at this time.
0 commit comments