diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 3e166a9..db244f1 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -4,7 +4,7 @@ name: Python package on: push: - branches: [ $default-branch ] + branches: [ main ] pull_request: jobs: @@ -12,8 +12,10 @@ jobs: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - python-version: [3.9, 3.11, 3.12] + # Note: Python 3.13 requires updated aiohttp and freezegun dependencies + python-version: ['3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v4 @@ -21,22 +23,26 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - # Install Docker Compose - - name: Install Docker Compose - run: | - sudo apt-get update - sudo apt-get install -y docker-compose # Start this early in case it needs some "boot up time" - name: Start docker containers for tests run: | - docker-compose up -d mock-tplink-api + docker compose up -d mock-tplink-api - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install flake8 pytest + python -m pip install flake8 pytest pytest-asyncio if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Wait for mock API to be ready + run: | + for i in {1..30}; do + if curl -s http://127.0.0.1:8080 > /dev/null 2>&1; then + echo "Mock API is ready" + break + fi + echo "Waiting for mock API... ($i/30)" + sleep 1 + done - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..2f4c80e --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +asyncio_mode = auto diff --git a/tests/conftest.py b/tests/conftest.py index b6f431e..578c1de 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,5 @@ import os import pytest -import asyncio try: from .local_env_vars import ENV_VARS @@ -20,10 +19,3 @@ def tests_setup_and_teardown(): # Will be executed after the last test os.environ.clear() os.environ.update(original_environ) - - -@pytest.fixture(scope='module') -def event_loop(request): - loop = asyncio.get_event_loop_policy().new_event_loop() - yield loop - loop.close() diff --git a/tests/test_device_manager.py b/tests/test_device_manager.py index 93999e5..7461a3d 100644 --- a/tests/test_device_manager.py +++ b/tests/test_device_manager.py @@ -18,7 +18,7 @@ async def client(): ) -@pytest.mark.usefixtures('client', 'event_loop') +@pytest.mark.usefixtures('client') class TestGetDevices(object): @pytest.mark.asyncio