From b25f428467015496da2f050c0ef0918983f1a34b Mon Sep 17 00:00:00 2001 From: Vladyslav Fedoriuk Date: Sat, 29 Jul 2023 12:23:26 +0200 Subject: [PATCH] Add coverage config --- .coveragerc | 2 ++ .github/workflows/app.yaml | 19 ++++++++++++++++++- app/conftest.py | 2 +- pyproject.toml | 1 + requirements/test.txt | 5 +++++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..c712d25 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,2 @@ +[run] +omit = tests/* diff --git a/.github/workflows/app.yaml b/.github/workflows/app.yaml index 420ed80..6de150f 100644 --- a/.github/workflows/app.yaml +++ b/.github/workflows/app.yaml @@ -16,7 +16,7 @@ jobs: - name: Install dev dependencies run: | python -m pip install --upgrade pip - pip install -r requirements/dev.txt + python -m pip install -r requirements/dev.txt - name: Lint with ruff uses: chartboost/ruff-action@v1 with: @@ -33,3 +33,20 @@ jobs: - name: Lint with pyproject-fmt run: | python -m pyproject_fmt --stdout --check --indent=4 + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: # https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages + python-version: '3.11' + cache: 'pip' + cache-dependency-path: 'requirements/test.txt' + - name: Install test dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements/test.txt + - name: Test with pytest + run: | + python -m pytest -v -s --failed-first --cov=app --cov-report=xml diff --git a/app/conftest.py b/app/conftest.py index e0ce4fe..ba61ebc 100644 --- a/app/conftest.py +++ b/app/conftest.py @@ -19,7 +19,7 @@ def anyio_backend() -> Literal["asyncio"]: @pytest.fixture(autouse=True) def test_db(mocker: MockerFixture) -> None: """Use the in-memory database for tests.""" - mocker.patch("app.database.DB_PATH", "sqlite+aiosqlite:///") + mocker.patch("app.database.SQLALCHEMY_DATABASE_URL", "sqlite+aiosqlite:///") @pytest.fixture(scope="session") diff --git a/pyproject.toml b/pyproject.toml index 7fedb00..367b82b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ test = [ "polyfactory", "pytest", "pytest-anyio", + "pytest-cov", "pytest-mock", ] diff --git a/requirements/test.txt b/requirements/test.txt index b15ca0a..96bc6e7 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -22,6 +22,8 @@ certifi==2023.7.22 # httpx click==8.1.6 # via uvicorn +coverage[toml]==7.2.7 + # via pytest-cov dirty-equals==0.6.0 # via awesome-fastapi-projects (pyproject.toml) dnspython==2.4.1 @@ -84,9 +86,12 @@ pytest==7.4.0 # via # awesome-fastapi-projects (pyproject.toml) # pytest-anyio + # pytest-cov # pytest-mock pytest-anyio==0.0.0 # via awesome-fastapi-projects (pyproject.toml) +pytest-cov==4.1.0 + # via awesome-fastapi-projects (pyproject.toml) pytest-mock==3.11.1 # via awesome-fastapi-projects (pyproject.toml) python-dateutil==2.8.2