From 146326e87dbaf02bcdc2eeb51d5ff16ec9024a7a Mon Sep 17 00:00:00 2001 From: Patrick Roddy Date: Fri, 8 Sep 2023 16:57:29 +0200 Subject: [PATCH] TST: Fix flaky test and don't fail fast (#20) Add `fail-fast` such that all `python` versions will finish before exiting. Add `pytest-rerunfailures` for the flaky test. Fixes: #19 Reviewed-by: @ntessore --- .github/workflows/test.yml | 5 ++++- pyproject.toml | 7 +++++++ tests/test_kmeans_radec.py | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 780bdc1..81ec70e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,6 +36,7 @@ jobs: name: Tests runs-on: ubuntu-latest strategy: + fail-fast: false matrix: python-version: ["3.9", "3.10", "3.11"] steps: @@ -43,8 +44,10 @@ jobs: - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + cache: "pip" + cache-dependency-path: "pyproject.toml" - run: pip install -c .github/test-constraints.txt '.[test]' - - run: pytest tests + - run: pytest build: name: Build runs-on: ubuntu-latest diff --git a/pyproject.toml b/pyproject.toml index 93f0b5a..b47cbd1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,7 @@ optional-dependencies = {docs = [ "sphinxcontrib-katex", ], test = [ "pytest", + "pytest-rerunfailures", ]} readme = "README.md" requires-python = ">=3.9" @@ -55,6 +56,12 @@ force-exclude = """ build.hooks.vcs.version-file = "heracles/_version.py" version.source = "vcs" +[tool.pytest.ini_options] +addopts = "--color=yes -v" +testpaths = [ + "tests", +] + [tool.ruff] extend-exclude = [ "_kmeans_radec.py", diff --git a/tests/test_kmeans_radec.py b/tests/test_kmeans_radec.py index f323065..8d089f1 100644 --- a/tests/test_kmeans_radec.py +++ b/tests/test_kmeans_radec.py @@ -1,3 +1,7 @@ +import pytest + + +@pytest.mark.flaky(reruns=2) def test_kmeans_sample(): import numpy as np