Skip to content
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

Improve import time test #508

Merged
merged 15 commits into from
Feb 12, 2025
19 changes: 13 additions & 6 deletions tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@


@pytest.mark.skipif(
not sys.platform.startswith("linux") or platform.python_implementation() == "PyPy",
not sys.platform.startswith("linux")
or platform.python_implementation() == "PyPy"
or sys.version_info[:2] == (3, 12),
reason="Unreliable",
)
def test_import_time(pytester: pytest.Pytester) -> None:
Expand All @@ -14,9 +16,14 @@ def test_import_time(pytester: pytest.Pytester) -> None:
from time to time, but this should provide an early warning if something is
added that significantly increases import time.
"""
r = pytester.run(
sys.executable, "-We", "-c", "import aiohttp_debugtoolbar", timeout=0.95
)
best_time_ms = 1000
cmd = "import timeit; print(int(timeit.timeit('import aiohttp_debugtoolbar', number=1)*1000))"
for _ in range(3):
r = pytester.run(sys.executable, "-We", "-c", cmd)

assert not r.stdout.str()
assert not r.stderr.str()
assert not r.stderr.str()
runtime_ms = int(r.stdout.str())
if runtime_ms < best_time_ms:
best_time_ms = runtime_ms

assert best_time_ms < 350
Loading