Skip to content

Commit 5edd58b

Browse files
committed
fix(ci): address Python 3.15 CI test failures and ensure 100% profiler coverage
1 parent 0009641 commit 5edd58b

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

.github/workflows/import-profiler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Run import profiler unit tests
3232
run: |
3333
python -m pip install --upgrade pip
34-
pip install pytest pytest-cov
34+
pip install pytest pytest-cov setuptools
3535
pytest scripts/import_profiler/test_profiler.py --cov=profiler --cov-report=term-missing --cov-fail-under=100
3636
- name: Run import profiler
3737
env:

scripts/import_profiler/test_profiler.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -475,21 +475,16 @@ def test_run_worker_and_parse_missing_key():
475475
_run_worker_and_parse(["python", "profiler.py"])
476476

477477

478-
def test_calculate_percentiles():
479-
from profiler import _calculate_percentiles
480-
assert _calculate_percentiles([]) == (0.0, 0.0, 0.0)
481-
assert _calculate_percentiles([5.0]) == (5.0, 5.0, 5.0)
482-
p50, p90, p99 = _calculate_percentiles(list(range(100)))
483-
assert p50 < p90 < p99
484-
485-
486-
def test_print_outputs_empty():
478+
def test_print_outputs_multiple_and_empty():
487479
from profiler import _print_outputs
488480
with patch("builtins.print") as mock_print:
489-
_print_outputs("math", 1, 10, 500, [], 0, 0, 0, [], 0, 0, 0, [], 0, 0, 0)
481+
_print_outputs("math", 1, 10, 500, [], [], [])
482+
_print_outputs("math", 2, 10, 500, [10.0, 12.0], [1.0, 2.0], [1.0, 2.0])
490483
assert mock_print.called
491484

492485

486+
487+
493488
def test_run_master_invalid_iterations():
494489
with pytest.raises(ValueError, match="Number of iterations must be at least 1"):
495490
run_master(0, "math")
@@ -644,6 +639,7 @@ def test_find_module_from_package_metadata_init():
644639

645640

646641
def test_find_module_from_package_setuptools():
642+
sys.modules.setdefault("setuptools", MagicMock())
647643
with patch("importlib.metadata.files", side_effect=Exception), \
648644
patch("os.path.exists", return_value=True), \
649645
patch("setuptools.find_namespace_packages", return_value=["google", "google.cloud", "tests.dummy", "my_pkg"]), \
@@ -653,8 +649,8 @@ def test_find_module_from_package_setuptools():
653649
assert res == "my_pkg"
654650

655651

656-
657652
def test_find_module_from_package_setuptools_not_file_and_exception():
653+
sys.modules.setdefault("setuptools", MagicMock())
658654
def mock_isfile(path):
659655
if "a_pkg" in path:
660656
return False
@@ -675,9 +671,8 @@ def mock_isfile(path):
675671
assert res == "my.pkg"
676672

677673

678-
679-
680674
def test_find_module_from_package_exception_in_find_spec():
675+
sys.modules.setdefault("setuptools", MagicMock())
681676
def mock_find_spec(mod):
682677
raise Exception("Find spec error")
683678

@@ -688,6 +683,7 @@ def mock_find_spec(mod):
688683
assert res == "foo.bar"
689684

690685

686+
691687
def test_cli_main_options():
692688
import runpy
693689

0 commit comments

Comments
 (0)