From 7dfa50e408dc346c37a9b1d929e7a724700586ce Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 20 Feb 2025 16:53:05 +0800 Subject: [PATCH 1/2] chore: fix benchmark import more accurate --- benchmark/test_import.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/benchmark/test_import.py b/benchmark/test_import.py index 846d72b25..9fc13dcbb 100644 --- a/benchmark/test_import.py +++ b/benchmark/test_import.py @@ -1,20 +1,18 @@ from __future__ import annotations +import importlib import subprocess import sys +from unittest import mock import pytest -@pytest.mark.benchmark -def test_import(): - """Test import dpdata.""" - subprocess.check_output( - [sys.executable, "-c", "'from dpdata import LabeledSystem'"] - ).decode("ascii") +@pytest.mark.parametrize("mod_name", ["dpdata", "dpdata.cli"]) +def test_bench_module_import(benchmark, mod_name): + """Benchmark the import time.""" - -@pytest.mark.benchmark -def test_cli(): - """Test dpdata command.""" - subprocess.check_output([sys.executable, "-m", "dpdata", "-h"]).decode("ascii") + @benchmark + def _(): + with mock.patch("sys.modules", {}): + importlib.import_module(mod_name, "test_bench_imports") From aedec44fdaa1e37738bd5876d7bebe9dd6a8a499 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 20 Feb 2025 08:53:30 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- benchmark/test_import.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/benchmark/test_import.py b/benchmark/test_import.py index 9fc13dcbb..871061e98 100644 --- a/benchmark/test_import.py +++ b/benchmark/test_import.py @@ -1,8 +1,6 @@ from __future__ import annotations import importlib -import subprocess -import sys from unittest import mock import pytest