| 1 |
# Orca Test Fixtures - Pytest Integration |
| 2 |
# |
| 3 |
# Copyright 2025 Igalia, S.L. |
| 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 |
"""Pytest fixtures for Orca screen reader tests. |
| 22 |
|
| 23 |
This module provides pytest fixtures that integrate the OrcaTestContext |
| 24 |
with pytest's fixture system, providing clean, isolated test environments. |
| 25 |
|
| 26 |
The fixtures are designed to be simple to use while providing complete |
| 27 |
test isolation and preventing cross-test contamination. |
| 28 |
|
| 29 |
Usage: |
| 30 |
def test_presenter(orca_test): |
| 31 |
orca_test.setup_where_am_i_presenter_dependencies() |
| 32 |
from orca.where_am_i_presenter import WhereAmIPresenter |
| 33 |
|
| 34 |
presenter = WhereAmIPresenter() |
| 35 |
result = presenter.some_method() |
| 36 |
assert result is True |
| 37 |
""" |
| 38 |
|
| 39 |
from __future__ import annotations |
| 40 |
|
| 41 |
from typing import TYPE_CHECKING |
| 42 |
|
| 43 |
import pytest |
| 44 |
|
| 45 |
from .orca_test_context import OrcaTestContext |
| 46 |
|
| 47 |
if TYPE_CHECKING: |
| 48 |
from collections.abc import Generator |
| 49 |
|
| 50 |
from pytest_mock import MockerFixture |
| 51 |
|
| 52 |
|
| 53 |
@pytest.fixture |
| 54 |
def test_context(mocker: MockerFixture, monkeypatch) -> Generator[OrcaTestContext, None, None]: |
| 55 |
"""Provides clean, isolated Orca test environment. |
| 56 |
|
| 57 |
This is the primary fixture for Orca tests. It provides a complete |
| 58 |
test isolation context that prevents cross-test contamination. |
| 59 |
|
| 60 |
Usage: |
| 61 |
class TestMyModule: |
| 62 |
def _setup_dependencies(self, orca_test): |
| 63 |
# Set up only what your module needs |
| 64 |
return orca_test.setup_shared_dependencies(["orca.debug"]) |
| 65 |
|
| 66 |
def test_my_functionality(self, orca_test): |
| 67 |
self._setup_dependencies(orca_test) |
| 68 |
from orca.my_module import MyClass |
| 69 |
|
| 70 |
# Your test code here |
| 71 |
instance = MyClass() |
| 72 |
result = instance.some_method() |
| 73 |
|
| 74 |
assert result is True |
| 75 |
|
| 76 |
Args: |
| 77 |
mocker: pytest-mock mocker fixture (automatically injected) |
| 78 |
monkeypatch: pytest monkeypatch fixture (automatically injected) |
| 79 |
|
| 80 |
Yields: |
| 81 |
OrcaTestContext instance with clean isolation |
| 82 |
""" |
| 83 |
|
| 84 |
with OrcaTestContext(mocker, monkeypatch) as context: |
| 85 |
yield context |