diff --git a/.gitea/workflows/integration-test.yml b/.gitea/workflows/integration-test.yml index ac3f2b4..a4d1fb1 100644 --- a/.gitea/workflows/integration-test.yml +++ b/.gitea/workflows/integration-test.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9','3.10','3.11','3.12','3.13'] + python-version: ['3.11', '3.12', '3.13'] home-assistant-version: ['2025.9.4'] steps: @@ -20,15 +20,58 @@ jobs: uses: actions/checkout@v4 - name: ๐Ÿ Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: ๐Ÿ“ฆ Install Home Assistant ${{ matrix.home-assistant-version }} + - name: ๐Ÿ—‚๏ธ Get pip cache directory + id: pip-cache-dir run: | + echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT + + - name: ๐Ÿ“ฆ Cache pip dependencies + uses: actions/cache@v4 + id: pip-cache + with: + path: ${{ steps.pip-cache-dir.outputs.dir }} + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements*.txt', 'setup.py', 'setup.cfg', 'pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-pip-${{ matrix.python-version }}- + ${{ runner.os }}-pip- + + - name: ๐Ÿ“ฆ Cache Home Assistant installation + uses: actions/cache@v4 + id: homeassistant-cache + with: + path: ${{ env.pythonLocation }} + key: ${{ runner.os }}-ha-${{ matrix.python-version }}-${{ matrix.home-assistant-version }}-${{ hashFiles('**/requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-ha-${{ matrix.python-version }}-${{ matrix.home-assistant-version }}- + ${{ runner.os }}-ha-${{ matrix.python-version }}- + + - name: ๐Ÿ“ฆ Install Dependencies + if: steps.homeassistant-cache.outputs.cache-hit != 'true' + run: | + python -m pip install --upgrade pip pip install homeassistant==${{ matrix.home-assistant-version }} - pip install pytest pytest-homeassistant-custom-component + pip install pytest pytest-homeassistant-custom-component pytest-asyncio pytest-cov + + - name: ๐Ÿ“ฆ Install additional dependencies (if cache miss) + if: steps.pip-cache.outputs.cache-hit != 'true' + run: | + # Install any additional project-specific dependencies + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi + + - name: ๐Ÿ“ Create custom_components directory + run: | + mkdir -p custom_components + touch custom_components/__init__.py - name: ๐Ÿงช Run Integration Tests run: | - python -m pytest tests/ -v --cov=custom_components/adguard_hub --cov-report=xml \ No newline at end of file + python -m pytest tests/ -v \ + --cov=custom_components/adguard_hub \ + --cov-report=xml \ + --cov-report=term-missing \ + --asyncio-mode=auto diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6c925a1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +homeassistant>=2025.9.4 +pytest>=7.0.0 +pytest-homeassistant-custom-component>=2025.9.0 +pytest-asyncio>=0.21.0 +pytest-cov>=4.0.0 \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..789dd86 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,7 @@ +import pytest + + +@pytest.fixture(autouse=True) +def auto_enable_custom_integrations(enable_custom_integrations): + """Enable custom integrations for all tests.""" + yield