diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 3f6e48a..1e48200 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -8,16 +8,22 @@ jobs: test: runs-on: ${{ matrix.os }} strategy: + + max-parallel: 1 + fail-fast: true matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-latest] python-version: ["3.10", "3.11", "3.12"] + env: TOGGL_WORKSPACE_ID: ${{ secrets.TOGGL_WORKSPACE_ID }} TOGGL_API_TOKEN: ${{ secrets.TOGGL_API_TOKEN }} + GH_ACTION: "ACTION" + steps: - - uses: actions/checkout@v3 - + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: @@ -27,8 +33,7 @@ jobs: run: | python -m pip install --upgrade pip pip install poetry - poetry install --with dev - pip install tox ruff mypy + pip install tox-gh-actions tox ruff mypy - name: Type check run: mypy toggl_api @@ -39,6 +44,12 @@ jobs: - name: Run tests run: tox + - name: Upload coverage reports to Codecov + if: ${{ matrix.python-version == '3.12' && matrix.os == 'ubuntu-latest' }} + uses: codecov/codecov-action@v4.0.1 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + build: needs: test runs-on: ubuntu-latest diff --git a/coverage.xml b/coverage.xml index 2f01686..adb33ff 100644 --- a/coverage.xml +++ b/coverage.xml @@ -1,22 +1,23 @@ - + /home/dk/dev/toggl-api-wrapper - + - - - - + + + + + @@ -104,7 +105,7 @@ - + @@ -115,7 +116,8 @@ - + + @@ -247,41 +249,28 @@ - + - - - - + + + + - - - - - + + - + - + - - - - - - - - - - @@ -853,7 +842,7 @@ - + @@ -981,7 +970,7 @@ - + @@ -998,38 +987,38 @@ - - - - - - + + - + + - - - + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/poetry.lock b/poetry.lock index 4ccdeb5..094d179 100644 --- a/poetry.lock +++ b/poetry.lock @@ -275,6 +275,9 @@ files = [ {file = "coverage-7.5.3.tar.gz", hash = "sha256:04aefca5190d1dc7a53a4c1a5a7f8568811306d7a8ee231c42fb69215571944f"}, ] +[package.dependencies] +tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} + [package.extras] toml = ["tomli"] @@ -1185,6 +1188,24 @@ tomli = {version = ">=1", markers = "python_version < \"3.11\""} [package.extras] dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +[[package]] +name = "pytest-cov" +version = "5.0.0" +description = "Pytest plugin for measuring coverage." +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-cov-5.0.0.tar.gz", hash = "sha256:5837b58e9f6ebd335b0f8060eecce69b662415b16dc503883a02f45dfeb14857"}, + {file = "pytest_cov-5.0.0-py3-none-any.whl", hash = "sha256:4f0764a1219df53214206bf1feea4633c3b558a2925c8b59f144f682861ce652"}, +] + +[package.dependencies] +coverage = {version = ">=5.2.1", extras = ["toml"]} +pytest = ">=4.6" + +[package.extras] +testing = ["fields", "hunter", "process-tests", "pytest-xdist", "virtualenv"] + [[package]] name = "pytest-env" version = "1.1.3" @@ -1794,4 +1815,4 @@ test = [] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "a49bf81e6c799b8323bbf29e26dba6bab2e0d31ef62c6941b9e7b70821273ab3" +content-hash = "f9cc51053b244a76c1b4d7f1ac7129adde037734edca210defe466f22cb0ef34" diff --git a/pyproject.toml b/pyproject.toml index 9113de4..8d2f603 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ pytest-sqlalchemy-mock = "^0.1.6" faker = "^25.2.0" pytest-reportlog = "^0.4.0" mkdocs-callouts = "^1.13.2" +pytest-cov = "^5.0.0" [tool.poetry.group.docs.dependencies] mkdocs = "^1.6.0" @@ -188,7 +189,7 @@ markers = [ "slow: Tests that are slow to run or have delays included.", ] testpaths = ["tests"] -addopts = "--report-log=logs/pytest.jsonl" +addopts = "--report-log=logs/pytest.jsonl --cov --cov-append --cov-report xml" [tool.tox] @@ -216,7 +217,6 @@ python = 3.10: py310 3.11: py311 3.12: ruff, mypy, py312 - 3.13: py313 [testenv:mypy] allowlist_externals = mypy, poetry diff --git a/tests/conftest.py b/tests/conftest.py index 55d23bf..6bed0ac 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,6 +2,7 @@ import contextlib import os +import time from datetime import datetime, timedelta, timezone from pathlib import Path @@ -20,6 +21,13 @@ from toggl_api.modules.workspace import WorkspaceEndpoint +@pytest.fixture(autouse=True) +def _rate_limit(): + yield + if os.environ.get("GH_ACTION"): + time.sleep(1) + + @pytest.fixture(scope="session") def faker(): return Faker() @@ -39,7 +47,8 @@ def cache_path(): path = Path(__file__).resolve().parents[0] / Path("cache") yield path if path.exists(): - cleanup(path) + with contextlib.suppress(PermissionError): + cleanup(path) @pytest.fixture(scope="session")