Skip to content

Move inline gi.require_version pins into each addon's tests/__init__.py #38

@eduralph

Description

@eduralph

Goal

Move the gi.require_version(...) GTK-version pins that currently live
inline at the top of individual addon test files into each addon's
tests/__init__.py, so the pin is declared once per addon and applied to
every test in that folder, on every launch path.

Why

Right now each GUI-touching test hand-rolls its own pin preamble. That has
three problems we've already been bitten by:

  1. It's easy to get partially wrong. PluginManager/tests/test_info_empty_requires.py
    pins Gtk but not Gdk — exactly the gap that made addons-source
    Form editor: guard save against mid-edit deletion of referenced objects (bug 11054) gramps-project/addons-source#926 warn-and-skip on a GTK-4-default host. One forgotten line per file is
    a latent, environment-dependent failure.
  2. It's repeated. ~13 test files carry the same boilerplate; a change to
    the contract (e.g. adding Pango) means editing every one.
  3. tests/__init__.py runs first anyway. Python imports
    <Addon>/tests/__init__.py before any <Addon>/tests/test_*.py, so the
    pin belongs there — it then covers a bare python3 -m unittest <Addon>.tests.<mod> run, not just runs under a specific harness.

Key constraint (addons-source-specific)

Addons are distributed individually, so the pin must be self-contained
in each addon's own tests/__init__.py
— we cannot use a shared
repo-level helper module (it wouldn't ship with the addon). This differs from
the testbed-side approach in
gramps-testbed#43,
which can use a shared helper. Here, each tests/__init__.py carries the
~6-line block directly.

What goes in tests/__init__.py

Mirror gramps/gen/constfunc.py (Gtk 3.0 and Gdk 3.0 together), pinning
silently — a failure here must not raise, or it aborts the whole package
import and every test errors instead of skipping cleanly:

"""Test package for <Addon>. Pins the GTK 3 stack before any test module
imports a gramps GUI/plugin module (the import chain loads Gtk; on a
GTK-4-default host an unpinned import binds the wrong version)."""
try:
    import gi

    gi.require_version("Gtk", "3.0")
    gi.require_version("Gdk", "3.0")
except (ImportError, ValueError):
    # No PyGObject / GTK 3 here; the test modules guard their own imports
    # and skip cleanly.
    pass

Then in each test module: delete the gi.require_version(...) lines, but
keep the existing try: import gramps ... except: raise SkipTest(...)
availability guard (that gates on whether gramps is importable at all, which
is still per-module). Template already in the wild:
RepositoriesReport/tests/__init__.py (addons-source gramps-project#929) uses exactly this
silent-pin pattern.

Inventory (machine-generated on maintenance/gramps61 — verify each)

Test files with an inline require_version to migrate (most pin
Gtk+Gdk; confirm per file):

  • CalculateEstimatedDates/tests/test_calculate_estimated_dates.py
  • DataEntryGramplet/tests/test_data_entry_gramplet.py
  • ImportMerge/tests/test_integration_importmerge.py
  • LifeLineChartView/tests/test_lifelinechart_tooltip_cache.py
  • SourceReferences/tests/test_sourcereferences_imports.py
  • Sqlite/tests/test_sqlite.py
  • SurnameMappingGramplet/tests/test_surnamemappinggramplet_imports.py
  • TMGimporter/tests/test_integration.py, TMGimporter/tests/test_libtmg.py
  • WebSearch/tests/test_filetable.py
  • WordleGramplet/tests/test_wordlegramplet_imports.py

Partial pin to fix while migrating (pins Gtk, missing Gdk):

  • PluginManager/tests/test_info_empty_requires.py

Assess whether these GUI-touching tests need the pin too (no pin today):

  • Form/tests/test_integration_form.py
  • FRWebConnectPack/tests/test_geneanet_url.py
  • PrerequisitesCheckerGramplet/tests/test_main_active_page_none.py

Dependencies / sequencing

  • Several addons still lack tests/__init__.py (e.g. CalculateEstimatedDates,
    DataEntryGramplet, TMGimporter). Gary's PR
    #931 adds five
    empty ones — those are the natural home; this issue fills them. Coordinate
    so we don't conflict with Add __init__.py to all unittest folders gramps-project/addons-source#931 (let it land, then add content).
  • The PR 820 pipeline's run_addon_tests.py pins Pango/PangoCairo/Gtk
    but not Gdk, so today the inline Gdk pins are what protect tests
    under the pipeline. Once the contract lives in tests/__init__.py this is
    belt-and-suspenders; either way, fixing run_addon_tests.py to add Gdk is
    the testbed-side counterpart (gramps-testbed#43).

Acceptance criteria

  • Every GUI-touching addon test folder has a tests/__init__.py pinning
    Gtk 3.0 + Gdk 3.0 (silently, no SkipTest from __init__).
  • No addon test module carries its own gi.require_version for the core GTK
    stack (grep */tests/test_*.py for require_version → only false-positive
    comments remain).
  • PluginManager's Gtk-only pin is resolved.
  • Each migrated addon's tests still pass via python3 -m unittest <Addon>.tests.<module> on both a Gdk-3-default and a Gdk-4-default
    interpreter.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions