Writing tests for Gedit plugin development (Python)

I (unsuccessfully) tried a Tox test automation setup, like this:

[tox]
envlist = py

[testenv]
description = Unit tests
sitepackages = true
deps =
    coverage[toml]
    pytest
commands =
    coverage run -m pytest {posargs:tests}
    coverage report

With a simple test, like this:

"""FILE: tests/test_plugin.py"""
from reST import ReStructuredTextPlugin

def test_init():
    """Can the plugin be instantiated successfully?"""
    plugin = ReStructuredTextPlugin()

The example plugin I try to run tests on is gedit-reST-plugin.

Notes

  1. The sitepackages = true is needed for import gi to be successful. I’d rather have Tox install the Python bindings as test dependencies, which would allow us to test against a variety of its versions (not just the one installed locally on the developer machine), but that requires development headers and various other preparation for PyGObject and Pycairo.

  2. Running a simple test still fails in at least two places (which are roughly import errors of various types), although the plugin runs successfully when used with Gedit on my Ubuntu 22.04.3 LTS machine.

    gi.require_version('Gedit', '3.0')
    

    causes ValueError: Namespace Gedit not available. When I comment out that line of code the test hits here next:

    from gi.repository import GObject, Gedit, PeasGtk
    

    causes ImportError: cannot import name Gedit, introspection typelib not found.

Is there a sensible way to work around those issues?