Skip to content

Achieve 100% test coverage and require it in CI#320

Open
KrzysztofMadejski wants to merge 3 commits into
python-injector:masterfrom
KrzysztofMadejski:coverage_100
Open

Achieve 100% test coverage and require it in CI#320
KrzysztofMadejski wants to merge 3 commits into
python-injector:masterfrom
KrzysztofMadejski:coverage_100

Conversation

@KrzysztofMadejski
Copy link
Copy Markdown

Summary

Brings injector/__init__.py to 100% line and branch coverage (previously ~97%) and raises the CI coverage gate to match, so future regressions fail PRs.

The previously-uncovered code fell into two buckets — string-formatting helpers and rarely-hit edge-case/error branches — plus one import-time branch.

Changes

1. Cover string-formatting / representation helpers

  • UnsatisfiedRequirement.__str__ — both the with-owner and without-owner branches
  • _describe — named objects, the tuple/list case, and the str() fallback
  • _get_origin — normalization of typing.List / typing.Dict aliases to builtins

2. Cover edge-case exception / branch paths

  • Binder.provider_for raising UnknownProvider for an unbindable target
  • @provider with an unresolvable forward-reference return annotation re-raising NameError at configure time
  • create_object wrapping a __new__ TypeError in a CallError
  • _infer_injected_bindings dropping Union members marked NoInject
  • Injector.get unwrapping a ScopeDecorator to its underlying scope
  • # pragma: no branch on the import-time logger-level guard — its else-branch is only reachable on a fresh import with a pre-set level, which can't be exercised in-process without importlib.reload corrupting shared marker state for the rest of the suite

3. Require 100% coverage

  • Bump --cov-fail-under from 90 to 100 in pytest.ini

Notes

The coverage-driven tests live in a dedicated injector_100_percent_coverage_test.py rather than injector_test.py, to keep the functional suite free of coverage-only edge cases.

🤖 Generated with Claude Code

KrzysztofMadejski and others added 3 commits June 3, 2026 22:15
Add a dedicated test module exercising the previously-uncovered
string-formatting paths in injector:

- UnsatisfiedRequirement.__str__ (with and without an owner)
- _describe (named objects, tuple/list, and the str() fallback)
- _get_origin normalization of typing.List/typing.Dict aliases

Kept separate from injector_test.py to avoid polluting the functional
suite with coverage-driven edge cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add tests for the remaining uncovered error/edge-case branches:

- Binder.provider_for raising UnknownProvider for an unbindable target
- Module configuration re-raising NameError for an unresolvable forward
  reference in a @Provider return annotation
- create_object wrapping a __new__ TypeError in a CallError
- _infer_injected_bindings dropping Union members marked NoInject
- Injector.get unwrapping a ScopeDecorator to its underlying scope

Also mark the import-time logger-level guard with `# pragma: no branch`:
its else-branch is only reachable on a fresh import with a pre-set level,
which can't be exercised in-process without importlib.reload corrupting
shared marker state for the rest of the suite.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Now that every line and branch in injector is exercised, raise the
--cov-fail-under gate from 90 to 100 so coverage regressions fail PRs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@KrzysztofMadejski
Copy link
Copy Markdown
Author

That's really surprising.. Why python package need testing on different ubuntu versions? That shouldn't be relevant at all.

build (ubuntu-latest, 3.10)Expected — Waiting for status to be reported
Required
build (ubuntu-latest, 3.11)
build (ubuntu-latest, 3.11)Expected — Waiting for status to be reported
Required
build (ubuntu-latest, 3.12)
build (ubuntu-latest, 3.12)Expected — Waiting for status to be reported
Required
build (ubuntu-latest, 3.13)
build (ubuntu-latest, 3.13)Expected — Waiting for status to be reported
Required
build (ubuntu-latest, 3.14)
build (ubuntu-latest, 3.14)Expected — Waiting for status to be reported
Required
build (ubuntu-latest, pypy3.10)
build (ubuntu-latest, pypy3.10)Expected — Waiting for status to be reported
Required
build (ubuntu-latest, pypy3.11)
build (ubuntu-latest, pypy3.11)Expected — Waiting for status to be reported

@KrzysztofMadejski
Copy link
Copy Markdown
Author

FYI @davidparsson

@davidparsson
Copy link
Copy Markdown
Collaborator

Why python package need testing on different ubuntu versions?

It's the same ubuntu version, but different Python versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants