Instruction file imported from JOHLC/Home-Assistant-Torque-OBDII (
.github/instructions/tests.instructions.md). Copyright stays with the author.
Test guidelines for this repository
Note: This repository now uses pytest for automated tests. The tests/ directory contains both automated tests and example payload data.
When adding or updating tests:
- Use pytest with Home Assistant's test utilities
- Tests must be isolated:
- Do not make network calls or access real OBD hardware
- Use pytest fixtures and mocks for the Torque app HTTP requests
- Mock Home Assistant core functions and state
- Naming:
- Test files: test_*.py
- Test functions: test_
- Coverage:
- Test sensor creation from Torque data
- Test PID mapping and unit conversion
- Test config flow validation
- Test error handling for invalid/missing data
- Assertions:
- Keep assertions specific and minimal
- Verify sensor states and attributes
- Fixtures:
- Put reusable fixtures in tests/conftest.py
- Create fixtures for mock Torque POST data (use tests/example-payload-data.md as reference)
- Create fixtures for Home Assistant test environment
- Fast and deterministic:
- Avoid sleeps/time-dependent flakiness
- Use Home Assistant's async test utilities
- Running tests:
- Use pytest -q tests or pytest --maxfail=1 tests
- Follow Home Assistant testing patterns from .github/home-assistant-developer-docs/
- Mocking Torque data:
- Provide reusable fixtures to simulate Torque HTTP POST requests
- Use example data from tests/example-payload-data.md
- Test with various PID combinations