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+ @pytest .mark .subprocess ()
55+ def test_slow_imports (monkeypatch ):
56+ # We should lazy load certain modules to avoid slowing down the startup
57+ # time when running in a serverless environment. This test will fail if
58+ # any of those modules are imported during the import of datadogpy.
59+
60+ blocklist = [
61+ 'configparser' ,
62+ 'email.mime.application' ,
63+ 'email.mime.multipart' ,
64+ 'importlib.metadata' ,
65+ 'importlib_metadata' ,
66+ 'logging.handlers' ,
67+ 'multiprocessing' ,
68+ 'urllib.request' ,
69+ ]
70+
71+ class BlockListFinder :
72+ def find_spec (self , fullname , * args ):
73+ for lib in blocklist :
74+ if fullname == lib :
75+ raise ImportError ('module %s was imported!' % fullname )
76+ return None
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