If you make a change to the NVDA code, you should run NVDA's automated tests. These tests help to ensure that code changes do not unintentionally break functionality that was previously working.
Pre-commit hooks can be used to automatically run linting, translatable string checks and unit tests on files staged for commit. This will automatically apply lint fixes where possible, and will cancel the commit on lint issues and other test failures.
From a shell, set up pre-commit scripts for your NVDA python environment:
venvUtils\ensureAndActivate.bat
pre-commit install
Alternatively, set up pre-commit scripts globally:
pip install pre-commit
pre-commit install --allow-missing-config
To skip pre-commit hooks from triggering, use the --no-verify
CLI option.
Example: git commit -m "message" --no-verify
.
You can run pre-commit hooks manually with pre commit run
.
- You can filter files with
--files
and--all-files
- You can also compare two revisions:
pre-commit run --from-ref origin/master --to-ref HEAD
To run the translatable string checks (which check that all translatable strings have translator comments), run:
scons checkPot
Our linting process involves running Ruff to pick up Python linting issues and auto-apply fixes where possible.
To run the linter locally:
runlint.bat
To be warned about linting errors faster, you may wish to integrate Ruff with your IDE or other development tools you are using.
Unit tests can be run with the rununittests.bat
script.
Internally this script uses the xmlrunner wrapper around the unittest framework to execute the tests.
Any arguments given to rununittests.bat
are forwarded onto xmlrunner, and then to unittest.
To run only specific unit tests, specify a pattern to match against using the -k
option on the command line.
The -k
option can be provided multiple times to provide multiple patterns to match against.
For example, to run only methods in the TestMove
and TestSelection
classes in the file tests\unit\test_cursorManager.py
file, run this command:
rununittests -k test_cursorManager.TestMove -k test_cursorManager.TestSelection
Please refer to unittest's documentation for further information on how to filter tests.
System tests can be run with the runsystemtests.bat --include <TAG>
script.
To run all tests standard tests for developers use runsystemtests.bat --include NVDA
.
Internally this script uses the Robot test framework to execute the tests.
Any arguments given to runsystemtests.bat
are forwarded onto Robot.
For more details (including filtering and exclusion of tests) see tests/system/readme.md
.
NVDA uses GPLv2 which is incompatible with certain licenses like Apache.
Run runlicensecheck.bat
to check that you don't introduce any new python dependencies with incompatible licenses.
This is configured in pyproject.toml using the licensecheck pip package.