Skip to content

Add pytest foundation and Zuul unit-test job - #234

Merged
ideaship merged 1 commit into
mainfrom
gh233
May 4, 2026
Merged

Add pytest foundation and Zuul unit-test job#234
ideaship merged 1 commit into
mainfrom
gh233

Conversation

@berendt

@berendt berendt commented May 3, 2026

Copy link
Copy Markdown
Member

Sets up the test infrastructure so per-module unit tests for netbox_manager/ can be added incrementally (foundation work for #232, implements #233): pytest config in pyproject.toml, tests/ tree at repo root with a dynaconf settings stub in conftest.py and a smoke test, new netbox-manager-unit-tests Zuul job in check / periodic-daily, and dev deps mirrored in Pipfile + test-requirements.txt. Also extends .gitignore to exclude pycache/, *.egg-info/, and .pytest_cache/.

Closes #233

AI-assisted: Claude Code

@ideaship ideaship left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Foundation is structurally sound: directory layout is correct, conftest.py handles the dynaconf import-time constraint cleanly, CI wiring is in place, and pipenv run pytest passes. Two items need to be fixed before merge.


Correctness bugs

1. Stale Pipfile.lock

pipenv verify reports the lock is out of date. The committed _meta.hash.sha256 does not match the current Pipfile. The Zuul job runs pipenv install --dev (without --deploy), which silently re-resolves and relocks rather than failing — so CI will drift away from the committed lock whenever a dependency has a newer release. Fix: run pipenv lock and commit the result, or add --deploy to the CI command to hard-fail on stale locks.

2. pytest==9.0.3 requires Python >=3.10; project declares requires-python = ">=3.8"

pytest==9.0.3 has Requires-Python: >=3.10. Modern pip resolves this at download time and will reject the install on Python 3.8/3.9, so the README instructions (pip install -r requirements.txt -r test-requirements.txt) are broken for those versions. The Zuul job also does not pin a Python version — issue #233 explicitly listed this as in-scope and recommended 3.13.

Fix: either pin Python >=3.10 (or 3.13 per the issue) in .zuul.yaml and document that the test suite requires Python 3.10+, or drop to a pytest version that supports 3.8+. The former is the cleaner path.


Missing / weak tests

3. get_leading_number has no behavioral test

test_main_module_imports only calls callable(main.get_leading_number). The function is pure and used in production paths (lines 975, 977 of main.py). A one-liner like assert main.get_leading_number("100-foo.yml") == "100" would provide an actual correctness check at zero extra cost.

4. test_main_module_importscallable(main.deep_merge) is redundant

test_deep_merge_smoke already calls deep_merge directly; if it were missing or broken, that test would fail. The callable() check adds nothing.

5. test_dtl_module_imports checks class existence, not behavior

hasattr(dtl, "Repo") / hasattr(dtl, "NetBox") / hasattr(dtl, "DeviceTypes") verify that three class names are present in the module namespace. No method on any of them is called. Acceptable for a pure smoke test, but worth noting as coverage expands under #232.


Minor

  • pyproject.toml excludes tests/ from mypy entirely. Issue #233 (open question 4) recommended including it with disable_error_code = ["no-untyped-def"]. Either choice is defensible; worth an explicit decision in the PR description.

@berendt
berendt force-pushed the gh233 branch 2 times, most recently from a179f6e to cf2290d Compare May 3, 2026 14:50
Sets up the test infrastructure so per-module unit tests for
netbox_manager/ can be added incrementally (foundation work for #232,
implements #233): pytest config in pyproject.toml, tests/ tree at repo
root with a dynaconf settings stub in conftest.py and smoke tests for
deep_merge and get_leading_number, new netbox-manager-unit-tests Zuul
job in check / periodic-daily, and dev deps mirrored in Pipfile +
test-requirements.txt. The Zuul job runs pipenv install --deploy --dev
so stale Pipfile.lock entries fail loudly instead of silently
re-resolving.

The pre-run playbook mirrors osism/python-osism: it uses the system
Python from the build node (Debian Bookworm's 3.11) and only installs
pipenv via apt, instead of pulling Python 3.13 from the deadsnakes
PPA. This removes a flaky external dependency on Launchpad — an
earlier run timed out fetching PPA metadata and failed the whole job
before tests could start.

Closes #233

AI-assisted: Claude Code

Signed-off-by: Christian Berendt <berendt@osism.tech>
@ideaship
ideaship merged commit f159c47 into main May 4, 2026
2 checks passed
@ideaship
ideaship deleted the gh233 branch May 4, 2026 14:50
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.

Introduce foundation for unit tests (pytest + Zuul CI integration)

3 participants