The unit tests need:
The integration tests additionally need the following dependencies. Some missing dependencies cause skips; others cause import or setup failures. Tests which launch Orca need an installed build of the version being tested.
- Xvfb and
python-xlib. pgrep(from procps) andfusermount.- The DejaVu Serif, DejaVu Sans, and DejaVu Sans Mono fonts, and the PangoCairo typelib.
dbus-run-session,gdbus, anddbus-update-activation-environment.- Python GObject introspection bindings (PyGObject).
- AT-SPI, including its typelib,
at-spi-bus-launcher, andat-spi2-registryd. glib-compile-schemas.- liblouis's Python bindings, en-us-g1/en-us-g2 tables, and build-time pkg-config
metadata (
liblouis-develon Fedora and openSUSE). - MathCAT enabled in the installed Orca build.
- GTK3 and GTK4, including their typelibs.
- Qt5 with PyQt5, and Qt6 with PySide6.
- Terminal support: Python
curses, xterm terminfo, and VTE with its GTK3 (2.91) and GTK4 (3.91) typelibs, plus Konsole. - Terminal applications:
bash,less,nano,vim, andseq(from coreutils). - Web browsers: Chrome (beta preferred) or Chromium, and Firefox (Nightly preferred).
- Document viewers: Atril.
- File managers: Caja, Dolphin, and Nautilus.
- Notifications:
notification-daemonandnotify-send(from libnotify).
pytest tests/unit_tests/ # All unit tests
coverage run -m pytest tests/unit_tests # Unit tests with coverage
python3 -m pytest tests/unit_tests/test_ax_text.py -v # Specific fileOrca's tests are grouped into the following named suites:
- "unit": the only suite run by default with
meson test - "integration": the superset of the following:
- "core": infrastructure such as GSettings, D-Bus support, and browser smoke tests
- "file-manager": file managers (Caja, Dolphin, and Nautilus)
- "caja": Caja file-manager tests
- "dolphin": Dolphin file-manager tests
- "nautilus": Nautilus file-manager tests
- "document": document viewers and editors (currently Atril)
- "gtk": all non-terminal GTK tests (both GTK3 and GTK4)
- "gtk3": non-terminal GTK3 UI tests
- "gtk4": non-terminal GTK4 UI tests
- "qt": all non-terminal Qt tests (both Qt5 and Qt6)
- "qt5": non-terminal Qt5 UI tests
- "qt6": non-terminal Qt6 UI tests
- "terminal": all terminal tests (GTK3 VTE, GTK4 VTE, and Konsole)
- "gtk3-terminal": for terminal applications using VTE for GTK3
- "gtk4-terminal": the same terminal tests using VTE for GTK4
- "konsole-terminal": for terminal applications using Konsole
- "web": all web-content tests (both Chromium and Firefox)
- "chromium": for web content using Chrome (beta preferred) or Chromium
- "gecko": for web content using Firefox (Nightly preferred)
Coverage for additional widgets and applications is in progress.
meson test -C _build
meson test -C _build --suite <suite name>
meson test -C _build --list --suite <suite name> # List tests without running themDownstream distributions may wish to run the small core suite to check basic
environment readiness. Failures in this suite can identify a dependency or
accessibility configuration problem that may need to be addressed downstream.
Such issues should be investigated before concluding the failure is a bug in Orca
or in its test harness. For example, browser accessibility may require
ACCESSIBILITY_ENABLED=1 (Chromium) or GNOME_ACCESSIBILITY=1 (Firefox) for the
browser to show up in the AT-SPI application registry. If AT-SPI doesn't know an
application exists, Orca cannot provide access to it. For this reason, the core
suite's browser smoke tests include coverage for the browser being launched without
the variables set in the environment to help identify this need.
The other integration-test suites are mainly intended for maintainer use for the purpose of preventing regressions in Orca. At the present time, the current stable versions of Fedora and openSUSE are officially supported. This is because the primary maintainer uses the former and CI uses the latter. Tests are expected to pass in other environments, but may fail due to something totally unrelated to accessibility, such as a different toolkit theme and/or font changing where a line wraps. Eliminating all such possible variants, and documenting all expected dependencies, versions, and configurations which may impact test results are still pending. In the meantime, such a failure should not be taken to mean there is anything wrong with that environment or Orca; just that something is different. Similarly, not being "officially supported" should not be taken to mean anything other than the fact that the maintainers have finite time and resources. If all of the integration tests pass (modulo flakes) on a distro not listed as supported, please let us know so that we can add it to a "known to work on" list.
The integration tests cannot run while Orca is already active on the user's
session because each test launches and drives its own Orca. It was decided
that the test harness should not first kill any running instance of Orca
because doing so might be unexpected. If you rely on Orca in your active
session, you can still run the tests by signing in as a second local user
(via su or ssh) and running them from there.
Most integration tests cover user interactions with applications and toolkits by simulating keystrokes, waiting for Orca's response, and checking the resulting speech and braille output. Running these tests therefore takes a fair amount of time. There are currently over 400 Meson test runs containing roughly 2,400 test cases, many involving numerous simulated keystrokes. CI divides the suites into separate container jobs that can run in parallel. Local runs do not require containers, and application tests run sequentially by default. A full local run can take a couple of hours, depending on the machine and installed applications.
Running tests directly on the local system is supported and tests the installed applications and toolkits. Supporting containers for local runs would add setup and maintenance requirements, along with resource management and validation for parallel runs. CI already provides container-based testing, so dedicated support for local containers is not currently planned.
ORCA_TEST_USER_AGENT_PATH overrides the browser executable. It must match the
selected suite; this is not checked by the harness. For example:
ORCA_TEST_USER_AGENT_PATH=/usr/bin/firefox meson test -C _build --suite gecko
ORCA_TEST_USER_AGENT_PATH=/opt/google/chrome-canary/chrome meson test -C _build --suite chromiumPrefer integration tests for new coverage. They exercise Orca with real applications and verify the speech and braille output associated with both native navigation and Orca commands.
Look for a related test in the appropriate directory under
tests/integration_tests/ and extend it when practical:
core/: infrastructure and browser accessibility smoke testsgtk/: widget tests shared between GTK3 and GTK4qt/: widget tests shared between Qt5 and Qt6terminal/: terminal tests for GTK3 VTE, GTK4 VTE, and Konsoleatril/: PDF-content tests in Atrilfile_manager/: file-manager tests for Caja, Nautilus, and Dolphinweb/: web-content tests shared between Chromium and Firefox
Otherwise, create a file named test_[feature].py in that directory,
following similar existing tests. Suite selection determines the toolkit
or browser; each shared test has a single source file.
Reuse the existing test applications in tests/integration_tests/apps/
and fixtures in tests/integration_tests/orca_fixtures.py when practical.
Web pages live in tests/integration_tests/web_pages/, and test documents
live in tests/integration_tests/documents/.
Simulate the user's key presses using the functions in
tests/integration_tests/harness/keyboard.py, such as tap_key() and
press_chord(), and check the resulting speech and braille. Existing
tests provide plenty of examples of native navigation and Orca commands.
Include relevant variations, such as navigating both forward and backward. For bug fixes, confirm that the test fails without the fix and passes with it.
Add each new test file to the appropriate group in orca_integration_tests
in tests/meson.build. Files in the web group run in both Chromium and
Firefox. Files in the gtk and terminal groups run in both GTK3 and GTK4.
Files in the qt group run in both Qt5 and Qt6.
Adding tests to an already registered file requires no Meson changes.
Build and install the version of Orca being tested, then run the affected tests with Meson. For example:
meson test -C _build --suite gtk3 test_gtk_caret_navigation
meson test -C _build --suite chromium test_web_code_block
meson test -C _build --suite gecko test_web_code_block_gecko
Run web tests in both browsers. See "Running Tests" above for the other suites and requirements.
Integration tests are preferred. Add unit tests only for behavior that cannot be adequately tested through integration tests.
Follow naming convention: test_[module_name].py
Add each new file to the unit_tests list in tests/meson.build.
from typing import TYPE_CHECKING
import pytest
if TYPE_CHECKING:
from .orca_test_context import OrcaTestContext
from unittest.mock import MagicMock
@pytest.mark.unit
class TestMyModule:
"""Test MyModule class methods."""
def _setup_dependencies(self, test_context: OrcaTestContext) -> dict[str, MagicMock]:
"""Set up mocks for my_module dependencies."""
# Use setup_shared_dependencies for common modules
additional_modules = ["orca.module_specific_to_my_module"]
essential_modules = test_context.setup_shared_dependencies(additional_modules)
# Configure module-specific behavior
my_mock = essential_modules["orca.module_specific_to_my_module"]
my_mock.some_method.return_value = "expected_value"
return essential_modules
def test_my_function(self, test_context: OrcaTestContext) -> None:
"""Test MyModule.my_function behavior."""
# Set up mocks BEFORE importing the module under test.
# Python's import system caches modules - if MyModule imports its
# dependencies before we mock them, it gets the real modules.
self._setup_dependencies(test_context)
# Import AFTER mocks are set up so MyModule gets our mocked dependencies.
from orca.my_module import MyModule
result = MyModule.my_function()
assert result == "expected_value"The test_context fixture provides testing utilities using pytest-mock patterns:
- Creates mock objects consistently across all tests
- Use
spec=when the class itself hasn't been replaced (even if you're mocking instances of it) - Omit
spec=for method replacements, function replacements, class replacements, and ad-hoc test data
# Use spec when the class itself hasn't been replaced
mock_accessible = test_context.Mock(spec=Atspi.Accessible)
mock_accessible.get_name.return_value = "Test Button"
# Mock a function and use the spec mock as return value
mock_match_rule_new = test_context.Mock()
test_context.patch("gi.repository.Atspi.MatchRule.new", side_effect=mock_match_rule_new)
mock_rule = test_context.Mock(spec=Atspi.MatchRule)
mock_match_rule_new.return_value = mock_rule
# Don't use spec when the class itself is being mocked
mock_state_set_class = test_context.Mock()
test_context.patch("gi.repository.Atspi.StateSet", new=mock_state_set_class)
mock_state_set = test_context.Mock() # StateSet class was replaced, can't use spec
mock_state_set_class.return_value = mock_state_set
# Don't use spec for method/function replacements
debug_mock.print_message = test_context.Mock()
mock_function = test_context.Mock()
test_context.patch("module.function", side_effect=mock_function)
# Don't use spec for ad-hoc test data
test_config = test_context.Mock()
test_config.enabled = True- Returns mock objects for assertions
- Use
patch()for string-based patching of deep module paths - Use
patch_object()for patching attributes on existing objects
mock_clear_cache = test_context.patch("gi.repository.Atspi.Accessible.clear_cache")
AXObject.clear_cache(mock_accessible, recursive=True)
mock_clear_cache.assert_called_once_with(mock_accessible)
mock_present_line = test_context.patch_object(presenter, "present_line")
presenter.go_previous_line(script_mock, event_mock)
mock_present_line.assert_called_once_with(script_mock, event_mock)- Use instead of
patch()orpatch_object()when you need to replace entire modules insys.modules - Useful when the module under test imports dependencies at module level
- Ensures the mock module is available when the test module imports it
# Single module replacement
mock_module = test_context.Mock()
test_context.patch_module("orca.special_module", mock_module)
# Multiple modules at once
test_context.patch_modules({"orca.module1": mock_module1, "orca.module2": mock_module2})- Patches environment variables for the test duration
- Can add new variables or remove existing ones
test_context.patch_env(
{"XDG_SESSION_TYPE": "wayland", "HOME": "/tmp/test"}, remove_vars=["DISPLAY"]
)Most tests should use test_context.setup_shared_dependencies() which provides
common modules.
Use pytest's parameterize decorator for testing multiple inputs efficiently.
For straightforward test cases:
@pytest.mark.parametrize(
"focus, window, expected",
[
pytest.param(None, None, True, id="both_none"),
pytest.param(None, "window", False, id="focus_none_window_set"),
pytest.param("focus", None, False, id="focus_set_window_none"),
pytest.param("focus", "window", False, id="both_set"),
],
)
def test_focus_and_window_are_unknown(self, test_context, focus, window, expected):
"""Test FocusManager.focus_and_window_are_unknown."""
self._setup_dependencies(test_context)
from orca.focus_manager import FocusManager
manager = FocusManager()
focus_obj = test_context.Mock(spec=Atspi.Accessible) if focus else None
window_obj = test_context.Mock(spec=Atspi.Accessible) if window else None
test_context.patch_object(manager, "_focus", new=focus_obj)
test_context.patch_object(manager, "_window", new=window_obj)
result = manager.focus_and_window_are_unknown()
assert result == expectedFor tests with complex configurations:
@pytest.mark.parametrize(
"case",
[
{
"id": "layout_only_role",
"mocks_config": {"ax_object.get_role": Atspi.Role.FILLER},
"expected": True,
},
{
"id": "group_with_explicit_name",
"mocks_config": {"ax_utilities_role.is_group": True, "has_explicit_name": True},
"expected": False,
},
{
"id": "layered_pane_in_desktop",
"mocks_config": {
"ax_utilities_role.is_layered_pane": True,
"ax_utilities_role.is_desktop_frame": True,
"ax_object.find_ancestor": "desktop",
},
"expected": True,
},
],
ids=lambda case: case["id"],
)
def test_is_layout_only_scenarios(self, test_context: OrcaTestContext, case: dict):
"""Test AXUtilities.is_layout_only with various scenarios."""
mocks_config = case["mocks_config"]
expected = case["expected"]
essential_modules = self._setup_dependencies(test_context)
for mock_path, mock_value in mocks_config.items():
if mock_path == "has_explicit_name":
test_context.patch(
"orca.ax_utilities.AXUtilities.has_explicit_name",
return_value=mock_value,
)
elif mock_path.startswith("ax_object.get_role"):
essential_modules["orca.ax_object"].AXObject.get_role = test_context.Mock(
return_value=mock_value
)
elif mock_path.startswith("ax_utilities_role."):
method_name = mock_path.split(".", 1)[1]
setattr(
essential_modules["orca.ax_utilities_role"].AXUtilitiesRole,
method_name,
test_context.Mock(return_value=mock_value),
)
from orca.ax_utilities import AXUtilities
mock_obj = test_context.Mock(spec=Atspi.Accessible)
result = AXUtilities.is_layout_only(mock_obj)
assert result is expectedBenefits of parameterized tests:
- Test multiple scenarios efficiently
- Clear test case identification
- Easy to add new test cases
- Better coverage with less code duplication
- Dictionary pattern keeps related test data together