Skip to content

tests: add test framework with mock and hardware support.#28

Merged
nedseb merged 1 commit intomainfrom
feat/test-framework
Mar 11, 2026
Merged

tests: add test framework with mock and hardware support.#28
nedseb merged 1 commit intomainfrom
feat/test-framework

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 11, 2026

Summary

  • Add a test framework combining mock tests (FakeI2C on CPython) and hardware tests (via mpremote)
  • Declarative YAML test scenarios per driver, auto-discovered by pytest
  • Markdown test reports with summary index + per-driver sub-reports
  • CI workflow (tests.yml) running mock tests on every push/PR
  • --driver and --port pytest options for targeted testing
  • Manual/interactive tests with display support, auto-skipped in non-interactive mode
  • First complete scenario: hts221.yaml (8 tests: mock + hardware + manual)
  • Updated README with Testing and Contributing sections

Usage

# Mock tests (CI, no hardware)
python -m pytest tests/ -v -k mock

# Hardware tests
python -m pytest tests/ -v --port /dev/ttyACM0

# Single driver
python -m pytest tests/ -v --driver hts221 --port /dev/ttyACM0

# Generate report
python -m pytest tests/ -v --port /dev/ttyACM0 --report auto

Closes #27

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a YAML-driven pytest framework to validate MicroPython drivers both on CPython (mocked I2C) and on real hardware via mpremote, with optional Markdown report generation and CI coverage for mock tests (closes #27).

Changes:

  • Introduces a generic scenario runner (tests/test_scenarios.py) that auto-discovers tests/scenarios/*.yaml and supports --driver / --port.
  • Adds hardware execution support via an mpremote bridge plus a FakeI2C/FakePin CPython shim for mock runs.
  • Adds a pytest Markdown report plugin and a GitHub Actions workflow to run mock tests in CI; updates README with Testing/Contributing guidance.

Reviewed changes

Copilot reviewed 15 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/test_scenarios.py Generic YAML scenario discovery + execution for mock/hardware/manual modes.
tests/scenarios/hts221.yaml First full driver scenario (HTS221) covering mock, hardware, and manual checks.
tests/runner/mpremote_bridge.py mpremote execution bridge to run driver calls / raw register reads on-device.
tests/runner/executor.py Scenario action execution + driver loading/cleanup for mock runs on CPython.
tests/report_plugin.py Pytest plugin generating Markdown summary + per-driver reports.
tests/fake_machine/i2c.py Fake I2C bus implementation for CPython-based driver tests.
tests/fake_machine/pin.py Fake Pin implementation for CPython-based driver tests.
tests/fake_machine/micropython_stub.py Minimal micropython.const() stub for CPython.
tests/fake_machine/init.py Exposes fake machine components for test harness.
tests/conftest.py Adds pytest options (--port, --driver) and enables the report plugin.
tests/requirements-test.txt Declares test dependencies for local installation.
pytest.ini Configures pytest testpaths and markers used by the framework.
.github/workflows/tests.yml CI workflow to run mock tests on push/PR.
.github/workflows/requirements.txt Adds pyyaml pin for workflow dependency installs.
README.md Documents how to run mock/hardware/manual tests and generate reports; expands contributing guidance.
reports/.gitkeep Keeps reports/ directory present for report output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/conftest.py Outdated
Comment thread .github/workflows/tests.yml Outdated
Comment thread tests/runner/mpremote_bridge.py
Comment thread tests/runner/mpremote_bridge.py Outdated
Comment thread tests/runner/mpremote_bridge.py
Comment thread tests/test_scenarios.py Outdated
@nedseb nedseb requested a review from Charly-sketch March 11, 2026 14:39
@nedseb nedseb force-pushed the feat/test-framework branch from f944691 to c4bb669 Compare March 11, 2026 15:20
@nedseb nedseb self-assigned this Mar 11, 2026
@nedseb nedseb added the enhancement New feature or request label Mar 11, 2026
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.0.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: Add test framework with mock and hardware support.

2 participants