| 1 |
# Orca |
| 2 |
# |
| 3 |
# Copyright 2025 Valve Corporation |
| 4 |
# Author: Joanmarie Diggs <[email protected]> |
| 5 |
# |
| 6 |
# This library is free software; you can redistribute it and/or |
| 7 |
# modify it under the terms of the GNU Lesser General Public |
| 8 |
# License as published by the Free Software Foundation; either |
| 9 |
# version 2.1 of the License, or (at your option) any later version. |
| 10 |
# |
| 11 |
# This library is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
# Lesser General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU Lesser General Public |
| 17 |
# License along with this library; if not, write to the |
| 18 |
# Free Software Foundation, Inc., Franklin Street, Fifth Floor, |
| 19 |
# Boston MA 02110-1301 USA. |
| 20 |
|
| 21 |
"""Shared fixtures and configuration for unit tests.""" |
| 22 |
|
| 23 |
from __future__ import annotations |
| 24 |
|
| 25 |
import os |
| 26 |
import sys |
| 27 |
from typing import TYPE_CHECKING |
| 28 |
|
| 29 |
from .orca_test_fixtures import test_context # noqa: F401 # pylint: disable=unused-import |
| 30 |
|
| 31 |
if TYPE_CHECKING: |
| 32 |
import pytest |
| 33 |
|
| 34 |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../src")) |
| 35 |
|
| 36 |
os.environ["GSETTINGS_BACKEND"] = "memory" |
| 37 |
|
| 38 |
|
| 39 |
def clean_all_orca_modules() -> None: |
| 40 |
"""Aggressively clean all orca modules from sys.modules.""" |
| 41 |
|
| 42 |
modules_to_remove = [ |
| 43 |
module_name |
| 44 |
for module_name in sys.modules |
| 45 |
if module_name.startswith("orca.") or module_name == "orca" |
| 46 |
] |
| 47 |
|
| 48 |
for module_name in modules_to_remove: |
| 49 |
sys.modules.pop(module_name, None) |
| 50 |
|
| 51 |
|
| 52 |
def pytest_configure(config: pytest.Config) -> None: |
| 53 |
"""Register custom markers.""" |
| 54 |
|
| 55 |
config.addinivalue_line("markers", "unit: marks tests as unit tests") |
| 56 |
|
| 57 |
|
| 58 |
def pytest_runtest_setup(item: pytest.Item) -> None: # pylint: disable=unused-argument |
| 59 |
"""Clean module cache before each test to prevent cross-test contamination.""" |
| 60 |
|
| 61 |
clean_all_orca_modules() |