Pendant mes essais pour l'ajout du support de FreeBSD à la CI de watchdog (via Cirrus CI et son fichier de configuration .cirrus.yml), je suis tombé sur cette erreur :

$ python3.7 -bb -m pytest tests
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.7/site-packages/pytest/__main__.py", line 7, in <module>
    raise SystemExit(pytest.main())
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 73, in main
    config = _prepareconfig(args, plugins)
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 224, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "/usr/local/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/usr/local/lib/python3.7/site-packages/_pytest/helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 794, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 1000, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 948, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 299, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/local/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 94, in load
    module = import_module(match.group('module'))
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "/usr/local/lib/python3.7/site-packages/_pytest/assertion/rewrite.py", line 143, in exec_module
    exec(co, module.__dict__)
  File "/usr/local/lib/python3.7/site-packages/pytest_cov/plugin.py", line 6, in <module>
    import coverage
  File "/usr/local/lib/python3.7/site-packages/coverage/__init__.py", line 15, in <module>
    from coverage.control import Coverage, process_startup
  File "/usr/local/lib/python3.7/site-packages/coverage/control.py", line 20, in <module>
    from coverage.data import CoverageData, combine_parallel_data
  File "/usr/local/lib/python3.7/site-packages/coverage/data.py", line 17, in <module>
    from coverage.sqldata import CoverageData
  File "/usr/local/lib/python3.7/site-packages/coverage/sqldata.py", line 15, in <module>
    import sqlite3
  File "/usr/local/lib/python3.7/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/lib/python3.7/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

Il semblerait que le module SQLite3 ne soit pas installé par défaut.

Pour corriger le tir :

$ pkg install -y python37 py37-sqlite3

Ensuite, Python démarrera correctement. Pour vérifier :

$ python3.7 -c 'import platform; print("Python", platform.python_version())'
Python 3.7.6
$ python3.7 -c 'import sqlite3; print("SQLite3", sqlite3.version)'
SQLite3 2.6.0

Voici le fichier de configuration utilisé (fichier .cirrus.yml) :

freebsd_instance:
  image_family: freebsd-12-1

task:
  install_script:
    - pkg install -y python37 py37-sqlite3
    # Print the Python version, only to be sure we are running the version we want
    - python3.7 -c 'import platform; print("Python", platform.python_version())'
    # Check SQLite3 is installed
    - python3.7 -c 'import sqlite3; print("SQLite3", sqlite3.version)'
  setup_script:
    - python3.7 -m ensurepip
    - python3.7 -m pip install -U pip
    - python3.7 -m pip install -r requirements-tests.txt
  lint_script:
    - python3.7 -m flake8 docs src tests tools
  tests_script:
    - python3.7 -bb -m pytest tests