Lopper Pytest Test Suite
This directory contains the pytest-based test suite for Lopper. This is a work-in-progress migration from the legacy lopper_sanity.py test framework.
Running Tests
Run all pytest tests
pytest tests/
Run with verbose output
pytest -v tests/
Run specific test file
pytest tests/test_tree.py
Run specific test class or function
pytest tests/test_tree.py::TestTreeWalking
pytest tests/test_tree.py::TestTreeWalking::test_tree_walk_no_exceptions
Run in parallel (faster)
pytest -n auto tests/
Run with coverage
pytest --cov=lopper --cov-report=html tests/
Test Structure
conftest.py- Shared fixtures and test configurationtest_tree.py- Tree walking and manipulation tests (migrated fromtree_sanity_test)test_yaml.py- YAML input/output and conversion tests (migrated fromyaml_sanity_test)test_fdt.py- FDT abstraction layer tests (migrated fromfdt_sanity_test)test_schema.py- Schema type detection tests (migrated fromschema_type_sanity_test)test_format.py- DTS format/output tests (migrated fromformat_sanity_test)test_lops.py- Lopper operations (lops) transformation tests (migrated fromlops_sanity_test)More test files will be added as migration continues…
Fixtures
Common fixtures available to all tests:
test_outdir- Temporary directory for test outputs (session-scoped)system_device_tree- Path to compiled test device tree (session-scoped)compiled_fdt- Compiled FDT object ready for testing (session-scoped)lopper_tree- Fresh LopperTree instance (function-scoped, one per test)lopper_sdt- Fresh LopperSDT instance for FDT tests (function-scoped)format_lopper_sdt- Fresh LopperSDT instance for format tests (function-scoped)schema_lopper_sdt- Fresh LopperSDT instance for schema tests (function-scoped)lops_device_tree- Fresh LopperSDT instance with lops for transformation tests (function-scoped)yaml_test_file- Path to YAML test file (session-scoped)
Migration Status
✅ Migrated (Complete 1:1 migrations)
Tree tests (
test_tree.py) - 42 tests covering completetree_sanity_test()from lopper_sanity.pyBasic tree walking and node counting
Tree printing with /memreserve/ preservation
Node access (by path, number, phandle)
Custom node lists and restricted walks
Subnode access methods
Reference resolution
Node string representation
Regex-based node and property finding
Tree manipulation (add/remove nodes and properties)
Tree resolve and export
Node deep copying
Property manipulation and access
Alias lookups
YAML tests (
test_yaml.py) - 6 tests covering completeyaml_sanity_test()from lopper_sanity.pyYAML load and write operations
YAML to tree conversion
Tree to DTS writing from YAML
Device tree to YAML conversion
Complex nested property access
FDT tests (
test_fdt.py) - 15 tests covering completefdt_sanity_test()from lopper_sanity.pyFDT export to dictionary representation
Loading tree from exported FDT
Tree sync and round-trip operations
Node and property deletion
Node and property addition
Tree and subnode iteration
String type detection in node printing
Schema tests (
test_schema.py) - 14 tests covering completeschema_type_sanity_test()from lopper_sanity.pySchema-based property type detection (8 types tested)
Property format preservation in output (6 patterns tested)
Format tests (
test_format.py) - 1 test covering completeformat_sanity_test()from lopper_sanity.pyDTS file writing with enhanced mode
Lops tests (
test_lops.py) - 18 tests covering completelops_sanity_test()from lopper_sanity.pyNode deletion, renaming, and addition via lops
Property removal, modification, and addition via lops
Selective and regex-based node output
Subtree operations (write, modify, move)
List property modifications (listval, liststring, singleval, singlestring)
📋 TODO
Lops tests (
test_lops.py) - Migratelops_sanity_test()andlops_code_test()Assists tests (
test_assists.py) - Migrateassists_sanity_test()OpenAMP tests (
test_openamp.py) - Migrateopenamp_sanity_test()
Benefits of Pytest
Better assertions: Clear failure messages showing expected vs actual
Fixtures: Reusable test setup without global state
Parametrization: Easy to test multiple inputs
Parallel execution: Run tests faster with
-n autoStandard tooling: Works with coverage tools, IDEs, CI systems
Test discovery: Just add files, no manual registration
Contributing
When adding new tests:
Create test file:
tests/test_<feature>.pyUse fixtures from
conftest.pyfor common setupFollow naming convention:
test_<what_it_tests>Add docstrings explaining what each test validates
Run locally before committing:
pytest tests/
See TODO.md in the root directory for the full migration plan.