From 0ed9861d1943b137bb7c478beb6d5a4599701b51 Mon Sep 17 00:00:00 2001 From: Rodolfo Olivieri Date: Fri, 22 Nov 2024 00:36:16 -0300 Subject: [PATCH] Add codecov test-results to detect flaky tests (#46) --- .github/workflows/unit-tests.yml | 17 ++++++++++++----- .gitignore | 1 + Makefile | 12 +++++++++--- pyproject.toml | 6 ++---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index a63dff2..4404542 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -17,6 +17,7 @@ jobs: - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 - uses: actions/setup-python@v5 with: @@ -29,15 +30,21 @@ jobs: cache: true - name: Install dependencies - run: make install + run: | + make install + echo "$(pdm venv --path in-project)/bin" >> $GITHUB_PATH - name: Run unit tests - run: pdm run unit-test - - - name: Generate coverage report - run: pdm run coverage + run: pdm run unit-test-coverage - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v5 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + # https://docs.codecov.com/docs/test-analytics + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 34f9fa0..13602a0 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ htmlcov/ # ignore tests specifics .tox coverage* +junit.xml diff --git a/Makefile b/Makefile index 91c6433..c111db3 100644 --- a/Makefile +++ b/Makefile @@ -14,11 +14,17 @@ install: install-tools ## Sync all required dependencies for Command Line Assist install-dev: install-tools ## Sync all development dependencies pdm sync --dev -unit-test: ## Unit test Command Line Assistant +unit-test: ## Unit test cla @echo "Running tests..." - @pytest tests --cov + @pytest @echo "Tests completed." +unit-test-coverage: ## Unit test cla with coverage + @echo "Running tests..." + @pytest --cov --junitxml=junit.xml -o junit_family=legacy + @echo "Tests completed." + + coverage: ## Generate coverage report from unit-tests @coverage xml @@ -36,5 +42,5 @@ clean: ## Clean project files @find . -name '__pycache__' -exec rm -fr {} + @find . -name '*.pyc' -exec rm -f {} + @find . -name '*.pyo' -exec rm -f {} + - @rm -rf .pdm-build .ruff_cache .coverage .pdm-python dist .tox + @rm -rf .pdm-build .ruff_cache .coverage .pdm-python dist .tox junit.xml coverage.xml @coverage erase diff --git a/pyproject.toml b/pyproject.toml index 68cb9bb..22ac431 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,13 +57,11 @@ lint.ignore = [ distribution = true [tool.pdm.scripts] -unit-test = "pdm run make unit-test" -coverage = "pdm run make coverage" - +unit-test = "make unit-test" +unit-test-coverage = "make unit-test-coverage" [tool.pytest.init_options] testpaths = ["tests"] -addopts = ["--cov-report=term-missing", "--cov-report=html"] [tool.coverage.report] skip_empty = true