8000 gh-118761: Add test_lazy_import for more modules by danielhollas · Pull Request #133057 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-118761: Add test_lazy_import for more modules #133057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 5, 2025
Prev Previous commit
Next Next commit
Add test_lazy_import for enum, functools, and email.utils
  • Loading branch information
danielhollas committed Apr 28, 2025
commit 97e8d478f9bf1b686a4e56283f9af194ae2f766b
10 changes: 10 additions & 0 deletions Lib/test/test_email/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
import time
import unittest

from test.support import cpython_only
from test.support.import_helper import ensure_lazy_imports


class TestImportTime(unittest.TestCase):

@cpython_only
def test_lazy_import(self):
ensure_lazy_imports("email.utils", {"random", "socket"})


class DateTimeTests(unittest.TestCase):

Expand Down
7 changes: 6 additions & 1 deletion Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from pickle import dumps, loads, PicklingError, HIGHEST_PROTOCOL
from test import support
from test.support import ALWAYS_EQ, REPO_ROOT
from test.support import threading_helper
from test.support import threading_helper, cpython_only
from test.support.import_helper import ensure_lazy_imports
from datetime import timedelta

python_version = sys.version_info[:2]
Expand Down Expand Up @@ -1274,6 +1275,10 @@ class Holiday(date, Enum):
IDES_OF_MARCH = 2013, 3, 15
self.Holiday = Holiday

@cpython_only
def test_lazy_import(self):
ensure_lazy_imports("enum", {"functools", "warnings", "inspect", "re"})

def test_bool(self):
# plain Enum members are always True
class Logic(Enum):
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from test.support import import_helper
from test.support import threading_helper
from test.support import cpython_only
from test.support import EqualToForwardRef

import functools
Expand Down Expand Up @@ -63,6 +64,14 @@ def __add__(self, other):
class MyDict(dict):
pass

class TestImportTime(unittest.TestCase):

@cpython_only
def test_lazy_import(self):
import_helper.ensure_lazy_imports(
"functools", {"os", "weakref", "typing", "annotationlib", "warnings"}
)


class TestPartial:

Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_pathlib/test_pathlib.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from urllib.request import pathname2url

from test.support import import_helper
from test.support import cpython_only
from test.support import is_emscripten, is_wasi
from test.support import infinite_recursion
from test.support import os_helper
Expand Down Expand Up @@ -129,6 +130,7 @@ class StrSubclass(str):
for part in p.parts:
self.assertIs(type(part), str)

@cpython_only
def test_lazy_import(self):
import_helper.ensure_lazy_imports("pathlib", {"shutil"})

Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def tearDown(self):
class ThreadTests(BaseTestCase):
maxDiff = 9999

@cpython_only
def test_lazy_import(self):
ensure_lazy_imports("threading", {"functools", "warnings"})

Expand Down
Loading
0