Add unit tests for osism/main.py (OsismApp entry point)#2382
Open
berendt wants to merge 2 commits into
Open
Conversation
6 tasks
fa2f7a6 to
03f8961
Compare
Cover the osism console-script entry point, which had no tests: - OsismApp.__init__: loguru's default handler is removed and a single stderr sink is added with level INFO, colorize, and the green-time format; the cliff App is wired to the osism.commands namespace, with deferred help, the "OSISM manager interface" description, a version passed through from the package (including the None fallback), and a working --version action that exits 0. - main: constructs the app once, forwards argv unchanged, and returns the app's exit code; the empty-argv edge is checked against a mocked app only. The loguru logger is patched before every construction so the process-global sink configuration is never mutated by the suite. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Christian Berendt <berendt@osism.tech>
The "if __name__ == '__main__'" script entry calls the real main() (and thus app.run with the process argv), so it cannot be exercised from an in-process unit test. Mark it "# pragma: no cover" so "pytest --cov=osism.main" reaches 100% and meets the >= 95% bar. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Christian Berendt <berendt@osism.tech>
03f8961 to
a30eb6d
Compare
Member
Author
Fix Report (iteration 1)Per check
Diff summary
StatusSTATUS: DONE_WITH_CONCERNS (Fix is high-confidence and grounded in direct source reading of cliff/argparse, but I could not execute pytest locally to see green — the local venv is broken and no interpreter here has the dependencies. The one concern a human should note: local verification was impossible, so confirmation depends on the next CI run.) Fix report generated by planwerk-review fix with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
tests/unit/test_main.py, the first coverage forosism/main.py— theosismconsole-script entry point. The module definesOsismApp(the cliffAppsubclass that wires theosism.commandsentry-point namespace andreplaces loguru's default sink) and
main()(theosism = osism.main:mainconsole script).
Closes #2361
Changes (in commit order)
Add unit tests for OsismApp and main in osism/main.py — creates
tests/unit/test_main.py:OsismApp.__init__— logging setup:logger.remove()is called once andlogger.add()is called once withsys.stderr,level="INFO",colorize=True, and the<green>{time:…}</green>format string. Theloguru
loggeris patched (mock_loggerfixture) before everyconstruction so the process-global sink is never mutated for real.
OsismApp.__init__— cliff wiring:command_manager.namespace == "osism.commands",deferred_help is True,parser.description == "OSISM manager interface", construction succeeds whenosism.main.__version__is patched toNone(the pbr fallback), andapp.run(["--version"])raisesSystemExit(0).main()— constructs the app exactly once, forwardsargvunchanged,returns the app's exit code (
42and0), and forwards an empty argvlist (asserted against a mocked app only — the real
app.run([])would enter cliff's interactive shell). A module docstring documents the
frozen
argv=sys.argv[1:]default so every test passesargvexplicitly.Exclude main entry guard in main.py from coverage — adds
# pragma: no coverto theif __name__ == "__main__":guard. That lineinvokes the real
main()/app.run()with the process argv and cannot beexercised in-process, so without the exclusion coverage tops out at
~94.4%. With it,
pytest --cov=osism.mainreaches 100%, satisfying the≥ 95 % Definition of Done. This commit is separable if a maintainer prefers
a
[coverage:report] exclude_linesblock insetup.cfginstead.Verification
flake8 tests/unit/test_main.py osism/main.py— clean.black --check tests/unit/test_main.py osism/main.py— clean.pytestis left to the Zuulpython-osism-unit-testsjob per the repo'slocal workflow (pipenv venv lives outside the tree).
Notes
command modules lazily. With the pinned
stevedore==5.8.0,CommandManageractually imports the
osism.commands.*tree eagerly; construction stillsucceeds in the unit environment (main deps installed,
tests/conftest.pystubs
ansible, stevedore skips per-plugin import errors), so everyassertion holds. The test comments avoid repeating the "cheap construction"
claim.
🤖 Generated with Claude Code