|
|
||
|---|---|---|
| .. | ||
| panasonic_heatpump | ||
| README.md | ||
| requirements.txt | ||
README.md
ESPHome Components Tests
This directory contains tests for all custom ESPHome components in this repository.
Directory Structure
tests/
├── requirements.txt # Common Python dependencies for all tests
├── panasonic_heatpump/ # Tests for panasonic_heatpump component
│ ├── README.md
│ ├── test_panasonic_heatpump_unit.py # Unit tests
│ ├── test_panasonic_heatpump_integration.py # Integration tests
│ ├── test_panasonic_heatpump_esp8266.yaml # ESP8266 test config
│ ├── test_panasonic_heatpump_esp32s2.yaml # ESP32-S2 test config
│ ├── test_panasonic_heatpump_esp32c3.yaml # ESP32-C3 test config
│ ├── test_panasonic_heatpump_cztaw1.yaml # CZ-TAW1 test config
│ ├── test_panasonic_heatpump_mini.yaml # Minimal ESP32 test config
│ └── test_panasonic_heatpump_full.yaml # Full ESP32 test config
└── [other_component]/ # Tests for other components (future)
Running Tests
Install Dependencies
pip install -r tests/requirements.txt
Run All Tests
pytest tests/ -v
Run Tests for Specific Component
# Panasonic Heatpump
pytest tests/panasonic_heatpump/ -v
# Other components (when added)
pytest tests/[component_name]/ -v
Run with Coverage
pytest tests/ -v --cov=components --cov-report=html
Adding Tests for New Components
When adding a new component, create a subdirectory under tests/ with the same name as your component:
- Create directory:
tests/[component_name]/ - Add test files:
test_[component_name].yaml- ESPHome configuration for testingtest_[component_name]_unit.py- Python unit teststest_[component_name]_integration.py- Integration testsREADME.md- Component-specific test documentation
- Create GitHub Actions workflow:
.github/workflows/test_[component_name].yml
Test Types
Unit Tests
- Test Python configuration validation
- Test component metadata
- Test schema structure
- Fast execution, no compilation required
Integration Tests
- Test ESPHome configuration validation
- Test actual firmware compilation
- Test various configuration scenarios
- Slower execution, requires ESPHome
Configuration
Test configuration is managed in pytest.ini at the repository root.
GitHub Actions
Each component should have its own GitHub Actions workflow in .github/workflows/ that:
- Validates ESPHome configurations
- Compiles test firmware
- Runs Python unit tests
- Checks code formatting
- Reports coverage
See panasonic_heatpump for a complete example.