diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab426b4..7812f0f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,14 +26,51 @@ jobs: architecture: x64 cache: 'pip' - - name: Install Poetry manager + - name: Install Poetry (Windows) + if: runner.os == 'Windows' + run: | + (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python - + echo "$HOME\AppData\Roaming\Python\Scripts" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + - name: Install Poetry (Unix) + if: runner.os != 'Windows' run: pip install --upgrade poetry - name: Install Dependencies run: poetry install - - name: Test with pytest + - name: Test with coverage + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' run: | - poetry run pytest --cov=transloadit tests + poetry run pytest --cov=transloadit \ + --cov-report=xml \ + --cov-report=json \ + --cov-report=html \ + --cov-report=term-missing \ + --cov-fail-under=65 \ + tests env: TEST_NODE_PARITY: 1 + + - name: Test without coverage + if: matrix.os != 'ubuntu-latest' || matrix.python-version != '3.12' + run: poetry run pytest tests + + - name: Upload coverage reports + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.xml + flags: unittests + name: python-sdk + fail_ci_if_error: true + + - name: Upload coverage artifacts + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' + uses: actions/upload-artifact@v4 + with: + name: coverage-reports + path: | + coverage.json + htmlcov/ diff --git a/README.md b/README.md index 0f775f5..4c9a243 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![Build status](https://github.com/transloadit/python-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/transloadit/python-sdk/actions/workflows/ci.yml) +[![Coverage](https://codecov.io/gh/transloadit/python-sdk/branch/main/graph/badge.svg)](https://codecov.io/gh/transloadit/python-sdk) # Transloadit python-sdk @@ -64,3 +65,11 @@ Then to run the tests: ```bash source .venv/bin/activate && poetry run pytest --cov=transloadit tests ``` + +Generate a coverage report with: + +```bash +poetry run pytest --cov=transloadit --cov-report=html tests +``` + +Then view the coverage report locally by opening `htmlcov/index.html` in your browser. \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index b44923c..99d051d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "pytransloadit" version = "1.0.0" -description = "A Python Integration for Transloadit’s file uploading and encoding service." +description = "A Python Integration for Transloadit's file uploading and encoding service." authors = ["Ifedapo Olarewaju"] maintainers = ["Florian Kuenzig", "Arnaud Limbourg"] license = "MIT" @@ -44,3 +44,24 @@ sphinx-autobuild = "^2021.3.14" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + +[tool.pytest.ini_options] +addopts = "--cov=transloadit --cov-report=term-missing" +testpaths = ["tests"] + +[tool.coverage.run] +source = ["transloadit"] +branch = true + +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "def __repr__", + "if self.debug:", + "raise NotImplementedError", + "if __name__ == .__main__.:", + "pass", + "raise ImportError", +] +ignore_errors = true +fail_under = 65