[python-package] [ci] allow ImportErrors from dependencies to be raised, expand testing of imports #7456

Open
jameslamb opened 2:11am on September 25, 2026 wants to merge 243 Ξ” into microsoft/lightgbm main from
python/lazy-imports-pt3
Reviewing
177 fewer changed lines
(53% less) vs GitHub
This saves about 92.8 hours per year vs conventional diff tools
jameslamb authored
of work between September 25 and October 11
Diff Delta:
243
About 24 Diff Delta/hour
Classified as:  Bug Fix, Feature Add, General

jameslamb's Description of Work

Contributes to #7327

Contributes to #7355

Closes #7169

Removes some try-catching in __init__.py that could make it harder to diagnose import issues (especially from dependencies).

To help with that, significantly expands testing of the optional-dependency handling in the Python package:


  • ensures test_basic.py can be run without any of lightgbm's optional dependencies + adds a CI job running it in an environment like that

  • adds explicit testing in CI that modules that should not be loaded are not loaded by import lightgbm

  • adds a statement coverage summary to Python test jobs (with pytest-cov) + enforcement of a coverage minimum (to ensure that all the test-skipping logic added in PRs like this doesn't accidentally lead to a loss of coverage in CI)

17 total changed files
(4 files ignored)
Loading changes...
Loading changes...
Loading changes...
Loading changes...
Loading changes...
Loading changes...
Loading changes...
Loading changes...
Loading changes...
Loading changes...
Loading changes...
Loading changes...
You’ve reached the end of the pull request
Like the credits, but with fewer stunts.