To force Mercurial to run your unit tests before each commit and not to allow committing unless the unit tests pass you can use the "precommit" hook.
In the repository root, edit the ".hg\hgrc" file and add the following lines:
[hooks]
precommit = path-to-tests-script
(e.g. "qtodotxt\test\runtests.py")
It is very important that if the unit tests fail the script will return an non-zero exit code, in the QTodoTxt test-runner script (you can the source here I do the following:
I run the standard python unittests:
tests = unittest.defaultTestLoader.discover('.',
pattern='test*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if not result.wasSuccessful():
exit_code = 1
for doctest_file in os.listdir(testsdir):
if doctest_file.endswith('.doctest'):
result = doctest.testfile(
os.path.join(testsdir, doctest_file))
if result.failed > 0:
exit_code = 2
sys.exit
method to return the correct exit code:sys.exit(exit_code)