|
| 1 | +import pytest |
| 2 | +from qgis.core import QgsApplication |
| 3 | +import os |
| 4 | +import sys |
| 5 | + |
| 6 | +# Legg til prosjekt-roten OG submodule-mappen i sys.path |
| 7 | +# slik at importer som 'import geovita_processing_plugin' og 'import Utils' fungerer |
| 8 | +project_root = os.path.abspath(os.path.dirname(__file__)) |
| 9 | +submodule_path = os.path.join(project_root, "geovita_processing_plugin", "REMEDY_GIS_RiskTool") |
| 10 | + |
| 11 | +sys.path.insert(0, project_root) |
| 12 | +sys.path.insert(0, submodule_path) |
| 13 | + |
| 14 | +@pytest.fixture(scope="session", autouse=True) |
| 15 | +def init_qgis_processing(qgis_app): |
| 16 | + """Initialiserer QGIS Processing framework og registrerer plugin-provider.""" |
| 17 | + |
| 18 | + print("Initializing QGIS Processing Framework...") |
| 19 | + try: |
| 20 | + from processing.core.Processing import Processing |
| 21 | + Processing.initialize() |
| 22 | + print("Processing Framework Initialized.") |
| 23 | + except ImportError as e: |
| 24 | + print(f"Could not import Processing: {e}") |
| 25 | + pytest.skip("Failed to import QGIS Processing framework") |
| 26 | + |
| 27 | + print("Registering Geovita provider...") |
| 28 | + try: |
| 29 | + # Nå som prosjekt-roten er i sys.path, kan vi importere den direkte |
| 30 | + from geovita_processing_plugin.geovita_processing_plugin_provider import Geovita_processing_pluginProvider |
| 31 | + provider = Geovita_processing_pluginProvider() |
| 32 | + |
| 33 | + if QgsApplication.processingRegistry().addProvider(provider): |
| 34 | + print(f"Successfully added provider: {provider.id()}") |
| 35 | + else: |
| 36 | + print("Failed to add provider.") |
| 37 | + except ImportError as e: |
| 38 | + print(f"Could not import Geovita provider: {e}") |
| 39 | + pytest.skip("Failed to import Geovita provider") |
| 40 | + |
| 41 | + yield |
| 42 | + |
| 43 | + # Nedrigging |
| 44 | + print("Deinitializing Processing Framework...") |
| 45 | + # Vi må sjekke om 'provider' ble definert i tilfelle importen feilet |
| 46 | + if 'provider' in locals() and provider: |
| 47 | + QgsApplication.processingRegistry().removeProvider(provider.id()) |
| 48 | + Processing.deinitialize() |
0 commit comments