Skip to content

Commit

Permalink
Add a basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
040medien committed Oct 29, 2024
1 parent 6c5423a commit c5610ef
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
--durations=10 \
-n auto \
--cov custom_components.stadtreinigung_hamburg \
--cov-report=term-missing \
-o console_output_style=count \
-p no:sugar \
tests
6 changes: 5 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[pytest]
asyncio_default_fixture_loop_scope = function
asyncio_mode = auto
testpaths = tests
python_files = test_*.py
python_classes = Test*
python_functions = test_*
Empty file added tests/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest_plugins = ["pytest_homeassistant_custom_component"]
25 changes: 25 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
from homeassistant.setup import async_setup_component
from homeassistant.const import STATE_UNKNOWN

@pytest.mark.asyncio
async def test_setup(hass, enable_custom_integrations):
"""Test that the component can be setup and creates sensors."""
config = {
'stadtreinigung_hamburg': {
'name': 'Test Sensor',
'street': 'Jungfernstieg',
'number': '1',
}
}
assert await async_setup_component(hass, 'stadtreinigung_hamburg', config)

Check failure on line 15 in tests/test_init.py

View workflow job for this annotation

GitHub Actions / Run tests

test_setup assert False
await hass.async_block_till_done()

# Check that the component is loaded
assert 'stadtreinigung_hamburg' in hass.config.components

# Verify that sensors are created
state = hass.states.get('sensor.test_sensor')
assert state is not None
assert state.state != STATE_UNKNOWN

0 comments on commit c5610ef

Please sign in to comment.