From 6f5f9a0bf8c90ee82017f4806fbbe7a78732b2db Mon Sep 17 00:00:00 2001 From: Alexander Minges Date: Tue, 8 Jul 2025 14:54:40 +0200 Subject: [PATCH] feat: migrate from Forgejo to GitLab CI with test reporting - Convert Forgejo workflow to GitLab CI/CD (.gitlab-ci.yml) - Add JUnit XML and coverage reporting with pytest-cov - Configure caching and artifacts for better CI performance - Fix pytest.ini configuration and enhance .coveragerc - Support GitLab v18.1.1 with comprehensive test visualization --- .coveragerc | 19 ++++++++++++++++--- .gitignore | 1 + .gitlab-ci.yml | 36 ++++++++++++++++++++++++++++++++++++ pytest.ini | 15 +++++++++++++++ requirements-dev.txt | 1 + setup.py | 3 ++- 6 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 pytest.ini diff --git a/.coveragerc b/.coveragerc index d898768..9b4d454 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,8 +1,12 @@ [run] source = doi2dataset -omit = +omit = */tests/* + */test_* */docs/* + */__pycache__/* + */venv/* + */.venv/* setup.py conf.py __init__.py @@ -11,13 +15,22 @@ omit = exclude_lines = pragma: no cover def __repr__ + def __str__ if self.debug: raise NotImplementedError + raise AssertionError if __name__ == .__main__.: + if TYPE_CHECKING: + @abstractmethod pass raise ImportError except ImportError - def __str__ + +show_missing = true +precision = 2 [html] -directory = htmlcov \ No newline at end of file +directory = htmlcov + +[xml] +output = coverage.xml diff --git a/.gitignore b/.gitignore index 73052a1..85ed911 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ htmlcov/ .cache nosetests.xml coverage.xml +junit.xml *.cover *.py,cover .hypothesis/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..376689d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,36 @@ +# GitLab CI/CD pipeline for doi2dataset +# Compatible with GitLab v18.1.1 + +stages: + - test + +variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + +cache: + paths: + - .cache/pip/ + - .venv/ + +test: + stage: test + image: python:3 + before_script: + - python -m pip install --upgrade pip + - pip install -r requirements.txt + - pip install -r requirements-dev.txt + script: + - pytest + artifacts: + reports: + junit: junit.xml + coverage_report: + coverage_format: cobertura + path: coverage.xml + paths: + - htmlcov/ + expire_in: 1 week + coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/' + only: + - branches + - merge_requests diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..c32678f --- /dev/null +++ b/pytest.ini @@ -0,0 +1,15 @@ +[pytest] +addopts = + --cov=doi2dataset + --cov-report=html + --cov-report=xml + --cov-report=term-missing + --junitxml=junit.xml + --verbose + --tb=short + +testpaths = tests + +python_files = test_*.py *_test.py +python_functions = test_* +python_classes = Test* diff --git a/requirements-dev.txt b/requirements-dev.txt index dfadb8c..ab30c10 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,4 @@ pytest>=8.3.5,<9.0 pytest-mock>=3.14.0,<4.0 +pytest-cov>=6.0.0,<7.0 ruff>=0.11.1,<0.20 diff --git a/setup.py b/setup.py index be93bdd..f88994f 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,8 @@ setup( ], "dev": [ "pytest>=8.3.5,<9.0", - "pytest-mock>=3.14.0,4.0", + "pytest-mock>=3.14.0,<4.0", + "pytest-cov>=6.0.0,<7.0", "ruff>=0.11.1,<0.20" ] },