Documentation for a newer release is available. View Latest

nvda.config

Reading and writing NVDA’s configuration, so a test can set up the exact state your add-on’s code path depends on.

def test_config_round_trips_through_a_real_nvda(nvda):
    original = nvda.config.get(("speech", "synth"))
    assert isinstance(original, str)
    snapshot = nvda.config.snapshot()
    assert "speech" in snapshot

snapshot() and restore() let a test change configuration for the duration of one test and put it back afterwards, without needing to know every key it touched:

def test_something_under_a_changed_setting(nvda):
    snapshot = nvda.config.snapshot()
    try:
        nvda.config.set(("speech", "symbolLevel"), "all")
        ...
    finally:
        nvda.config.restore(snapshot)