Skip to content

Commit 517129d

Browse files
committed
CI: rewrite test harness to unittest per AGENTS.md
The previous harness used pytest for fixtures, markers, and discovery. AGENTS.md mandates the stdlib unittest framework, so this replaces the pytest scaffolding with equivalent unittest constructs. - Remove pytest.ini and the root conftest.py (pytest-specific). - Replace tests/conftest.py with tests/gramps_test_env.py, a regular helper module that bootstraps sys.path / GRAMPS_RESOURCES at import and exposes two base classes: GrampsTestCase (session-cached plugin manager + registry via setUpClass) and GrampsDbTestCase (same plus a fresh in-memory SQLite DB per test). - Rewrite tests/test_plugin_registration.py as four unittest.TestCase subclasses (TestPluginRegistration, TestPluginLoading, TestImportPluginSmoke, TestExportPluginSmoke). pytest.fail(...) calls become self.fail(...); fixture injection becomes self.plugin_registry populated in setUpClass. - Add GPL header to tests/__init__.py (was empty). - Annotate all helpers and test methods with Python 3.10+ type hints; add Sphinx :param:/:returns: markers; add #---- class-header dividers. - .github/workflows/ci.yml: replace `python3 -m pytest` invocations with `python3 -m unittest` using explicit module lists. Unit-test jobs build the module list via a shell loop that skips test_integration*.py and Sqlite/tests/test_sqlite.py; integration job uses `unittest discover` on tests/ plus an explicit list of per-addon integration modules. - Drop the pytest `gui` marker mechanism — tests that require GTK now self-skip at import time via unittest.SkipTest (see the per-addon test files). - Remove pytest from the CI Dockerfile and from .github/environment.yml; unittest is stdlib so no install is needed. All touched files are Black-formatted. Issue #9393.
1 parent 0301fb3 commit 517129d

9 files changed

Lines changed: 353 additions & 369 deletions

File tree

.github/docker/gramps-ci/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# - GTK typelibs (so addon modules that `from gi.repository import Gtk`
66
# at module load time are importable — widgets still need xvfb to render)
77
# - intltool/gettext/git for make.py builds
8-
# - ruff, pytest, dbf for lint/test tooling
8+
# - ruff, dbf for lint/test tooling (tests use stdlib unittest per AGENTS.md)
99
# - xvfb + xauth for tests that actually render (wrap with `xvfb-run`)
1010
#
1111
# No display server runs by default — the image is headless unless a command
@@ -42,7 +42,6 @@ RUN pip install --no-cache-dir \
4242
pycairo \
4343
"gramps>=6.0,<6.1" \
4444
orjson \
45-
pytest \
4645
ruff \
4746
dbf
4847

.github/environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ dependencies:
99
- pip:
1010
- "gramps>=6.0,<6.1"
1111
- orjson
12-
- pytest
1312
- dbf

.github/workflows/ci.yml

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,24 @@ jobs:
9595
env:
9696
PYTHONPATH: .
9797
run: |
98-
test_dirs=""
99-
for d in */tests/; do
100-
if ls "$d"/test_*.py 1>/dev/null 2>&1; then
101-
test_dirs="$test_dirs $d"
102-
fi
98+
modules=""
99+
for f in */tests/test_*.py; do
100+
[ -f "$f" ] || continue
101+
case "$(basename "$f")" in
102+
test_integration*) continue ;;
103+
esac
104+
case "$f" in
105+
Sqlite/tests/test_sqlite.py) continue ;;
106+
esac
107+
mod="${f%.py}"
108+
mod="${mod//\//.}"
109+
modules="$modules $mod"
103110
done
104-
if [ -n "$test_dirs" ]; then
105-
echo "Running unit tests in: $test_dirs"
106-
python3 -m pytest $test_dirs -v --tb=short \
107-
--ignore-glob='**/test_integration*.py' \
108-
--ignore=Sqlite/tests/test_sqlite.py \
109-
-m 'not gui'
111+
if [ -n "$modules" ]; then
112+
echo "Running unit tests:$modules"
113+
python3 -m unittest -v $modules
110114
else
111-
echo "No per-addon unit test files found"
115+
echo "No per-addon unit test modules found"
112116
fi
113117
114118
# -----------------------------------------------------------------
@@ -135,26 +139,30 @@ jobs:
135139
run: |
136140
mamba info
137141
mamba list | head -30
138-
python -c "import pytest, gramps, gi; print('deps OK')"
142+
python -c "import gramps, gi; print('deps OK')"
139143
140144
- name: Run per-addon unit tests
141145
env:
142146
PYTHONPATH: .
143147
run: |
144-
test_dirs=""
145-
for d in */tests/; do
146-
if ls "$d"/test_*.py 1>/dev/null 2>&1; then
147-
test_dirs="$test_dirs $d"
148-
fi
148+
modules=""
149+
for f in */tests/test_*.py; do
150+
[ -f "$f" ] || continue
151+
case "$(basename "$f")" in
152+
test_integration*) continue ;;
153+
esac
154+
case "$f" in
155+
Sqlite/tests/test_sqlite.py) continue ;;
156+
esac
157+
mod="${f%.py}"
158+
mod="${mod//\//.}"
159+
modules="$modules $mod"
149160
done
150-
if [ -n "$test_dirs" ]; then
151-
echo "Running unit tests in: $test_dirs"
152-
python -m pytest $test_dirs -v --tb=short \
153-
--ignore-glob='**/test_integration*.py' \
154-
--ignore=Sqlite/tests/test_sqlite.py \
155-
-m 'not gui'
161+
if [ -n "$modules" ]; then
162+
echo "Running unit tests:$modules"
163+
python -m unittest -v $modules
156164
else
157-
echo "No per-addon unit test files found"
165+
echo "No per-addon unit test modules found"
158166
fi
159167
160168
# -----------------------------------------------------------------
@@ -173,23 +181,24 @@ jobs:
173181
- name: Run plugin registration tests
174182
env:
175183
PYTHONPATH: .
176-
run: python3 -m pytest tests/ -v --tb=short
184+
run: python3 -m unittest discover -s tests -p "test_*.py" -t . -v
177185

178186
- name: Run per-addon integration tests
179187
env:
180188
PYTHONPATH: .
181189
run: |
182-
integration_tests=""
183-
for f in */tests/test_integration*.py */test_integration*.py; do
184-
if [ -f "$f" ]; then
185-
integration_tests="$integration_tests $f"
186-
fi
190+
modules=""
191+
for f in */tests/test_integration*.py; do
192+
[ -f "$f" ] || continue
193+
mod="${f%.py}"
194+
mod="${mod//\//.}"
195+
modules="$modules $mod"
187196
done
188-
if [ -n "$integration_tests" ]; then
189-
echo "Running per-addon integration tests: $integration_tests"
190-
python3 -m pytest $integration_tests -v --tb=short
197+
if [ -n "$modules" ]; then
198+
echo "Running per-addon integration tests:$modules"
199+
python3 -m unittest -v $modules
191200
else
192-
echo "No per-addon integration test files found"
201+
echo "No per-addon integration test modules found"
193202
fi
194203
195204
# -----------------------------------------------------------------

conftest.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

pytest.ini

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Gramps - a GTK+/GNOME based genealogy program
3+
#
4+
# Copyright (C) 2026 Eduard Ralph
5+
#
6+
# This program is free software; you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation; either version 2 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
#
20+
21+
"""Package marker for the repo-wide Gramps addon test suite."""

tests/conftest.py

Lines changed: 0 additions & 160 deletions
This file was deleted.

0 commit comments

Comments
 (0)