From be3e29fb3cdc1c7858dac0d54ad67edd2ac30d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 3 Nov 2022 21:00:29 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Switch=20from=20Codecov=20to=20S?= =?UTF-8?q?mokeshow=20plus=20pytest-cov=20to=20pure=20coverage=20for=20int?= =?UTF-8?q?ernal=20tests=20(#5583)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/smokeshow.yml | 35 +++++++++++++++++++++++++++++ .github/workflows/test.yml | 40 +++++++++++++++++++++++++++++++-- pyproject.toml | 11 ++++++++- scripts/test-cov-html.sh | 5 ++++- scripts/test.sh | 2 +- 5 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/smokeshow.yml diff --git a/.github/workflows/smokeshow.yml b/.github/workflows/smokeshow.yml new file mode 100644 index 0000000000000..606633a99dece --- /dev/null +++ b/.github/workflows/smokeshow.yml @@ -0,0 +1,35 @@ +name: Smokeshow + +on: + workflow_run: + workflows: [Test] + types: [completed] + +permissions: + statuses: write + +jobs: + smokeshow: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - run: pip install smokeshow + + - uses: dawidd6/action-download-artifact@v2 + with: + workflow: test.yml + commit: ${{ github.event.workflow_run.head_sha }} + + - run: smokeshow upload coverage-html + env: + SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage} + SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 100 + SMOKESHOW_GITHUB_CONTEXT: coverage + SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + SMOKESHOW_AUTH_KEY: ${{ secrets.SMOKESHOW_AUTH_KEY }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9e492c1adacf8..7f87be700b0e6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,43 @@ jobs: run: pip install -e .[all,dev,doc,test] - name: Lint run: bash scripts/lint.sh + - run: mkdir coverage - name: Test run: bash scripts/test.sh - - name: Upload coverage - uses: codecov/codecov-action@v3 + env: + COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }} + CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }} + - name: Store coverage files + uses: actions/upload-artifact@v3 + with: + name: coverage + path: coverage + coverage-combine: + needs: [test] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Get coverage files + uses: actions/download-artifact@v3 + with: + name: coverage + path: coverage + + - run: pip install coverage[toml] + + - run: ls -la coverage + - run: coverage combine coverage + - run: coverage report + - run: coverage html --show-contexts --title "Coverage for ${{ github.sha }}" + + - name: Store coverage HTML + uses: actions/upload-artifact@v3 + with: + name: coverage-html + path: htmlcov diff --git a/pyproject.toml b/pyproject.toml index ad088ce33527f..d7b848502c12e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ Documentation = "https://fastapi.tiangolo.com/" [project.optional-dependencies] test = [ "pytest >=7.1.3,<8.0.0", - "pytest-cov >=2.12.0,<5.0.0", + "coverage[toml] >= 6.5.0,<7.0", "mypy ==0.982", "flake8 >=3.8.3,<6.0.0", "black == 22.8.0", @@ -147,3 +147,12 @@ filterwarnings = [ # TODO remove pytest-cov 'ignore::pytest.PytestDeprecationWarning:pytest_cov', ] + +[tool.coverage.run] +parallel = true +source = [ + "docs_src", + "tests", + "fastapi" +] +context = '${CONTEXT}' diff --git a/scripts/test-cov-html.sh b/scripts/test-cov-html.sh index 7957277fc354f..d1bdfced2abc5 100755 --- a/scripts/test-cov-html.sh +++ b/scripts/test-cov-html.sh @@ -3,4 +3,7 @@ set -e set -x -bash scripts/test.sh --cov-report=html ${@} +bash scripts/test.sh ${@} +coverage combine +coverage report --show-missing +coverage html diff --git a/scripts/test.sh b/scripts/test.sh index d445ca174200b..62449ea41549b 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -6,4 +6,4 @@ set -x # Check README.md is up to date python ./scripts/docs.py verify-readme export PYTHONPATH=./docs_src -pytest --cov=fastapi --cov=tests --cov=docs_src --cov-report=term-missing:skip-covered --cov-report=xml tests ${@} +coverage run -m pytest tests ${@}