Debian Codegraph @

test/conftest.py

raw
1 #!/usr/bin/env python3
2 #
3 # This file is formatted with ruff format
4 #
5
6 from pathlib import Path
7 import logging
8 import os
9 import pytest
10
11 from . import WacomDatabase
12
13 logger = logging.getLogger(__name__)
14
15
16 def load_test_db() -> WacomDatabase:
17 try:
18 dbpath = os.environ.get("MESON_SOURCE_ROOT")
19 if dbpath is None and (Path.cwd() / "meson.build").exists():
20 dbpath = Path.cwd()
21 logger.info(f"Defaulting to MESON_SOURCE_ROOT={dbpath}")
22 return WacomDatabase(path=Path(dbpath) / "data" if dbpath else None)
23 except AttributeError as e:
24 pytest.exit(
25 f"Failed to initialize and wrap libwacom.so: {e}. You may need to set LD_LIBRARY_PATH and optionally MESON_SOURCE_ROOT"
26 )
27
28
29 @pytest.fixture()
30 def db():
31 return load_test_db()