Add coverage config

This commit is contained in:
Vladyslav Fedoriuk 2023-07-29 12:23:26 +02:00
parent 4c4dabb96c
commit b25f428467
5 changed files with 27 additions and 2 deletions

2
.coveragerc Normal file
View File

@ -0,0 +1,2 @@
[run]
omit = tests/*

View File

@ -16,7 +16,7 @@ jobs:
- name: Install dev dependencies - name: Install dev dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install -r requirements/dev.txt python -m pip install -r requirements/dev.txt
- name: Lint with ruff - name: Lint with ruff
uses: chartboost/ruff-action@v1 uses: chartboost/ruff-action@v1
with: with:
@ -33,3 +33,20 @@ jobs:
- name: Lint with pyproject-fmt - name: Lint with pyproject-fmt
run: | run: |
python -m pyproject_fmt --stdout --check --indent=4 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

View File

@ -19,7 +19,7 @@ def anyio_backend() -> Literal["asyncio"]:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def test_db(mocker: MockerFixture) -> None: def test_db(mocker: MockerFixture) -> None:
"""Use the in-memory database for tests.""" """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") @pytest.fixture(scope="session")

View File

@ -31,6 +31,7 @@ test = [
"polyfactory", "polyfactory",
"pytest", "pytest",
"pytest-anyio", "pytest-anyio",
"pytest-cov",
"pytest-mock", "pytest-mock",
] ]

View File

@ -22,6 +22,8 @@ certifi==2023.7.22
# httpx # httpx
click==8.1.6 click==8.1.6
# via uvicorn # via uvicorn
coverage[toml]==7.2.7
# via pytest-cov
dirty-equals==0.6.0 dirty-equals==0.6.0
# via awesome-fastapi-projects (pyproject.toml) # via awesome-fastapi-projects (pyproject.toml)
dnspython==2.4.1 dnspython==2.4.1
@ -84,9 +86,12 @@ pytest==7.4.0
# via # via
# awesome-fastapi-projects (pyproject.toml) # awesome-fastapi-projects (pyproject.toml)
# pytest-anyio # pytest-anyio
# pytest-cov
# pytest-mock # pytest-mock
pytest-anyio==0.0.0 pytest-anyio==0.0.0
# via awesome-fastapi-projects (pyproject.toml) # via awesome-fastapi-projects (pyproject.toml)
pytest-cov==4.1.0
# via awesome-fastapi-projects (pyproject.toml)
pytest-mock==3.11.1 pytest-mock==3.11.1
# via awesome-fastapi-projects (pyproject.toml) # via awesome-fastapi-projects (pyproject.toml)
python-dateutil==2.8.2 python-dateutil==2.8.2