Mercurial > hg
annotate tests/silenttestrunner.py @ 47584:ee1fc8f970e6
run-tests: introduce a `HGTEST_REAL_HG` variable for test
It turns out that currently, `hg` and `which hg` can point to different things
because `hg` is an alias… This is annoying because script and pieces of test
are unknowingly using the wrong `hg`.
We will fix it in another changeset. However some test actually need to use a
real `hg` binary and not some `chg` or `rhg` equivalent. So we introduce a new
variable with the right value and we put it to us in the appropriate location.
Differential Revision: https://phab.mercurial-scm.org/D11049
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 09 Jul 2021 20:03:46 +0200 |
parents | 2372284d9457 |
children | 6000f5b25c9b |
rev | line source |
---|---|
28730
73437077753c
py3: use print_function in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28729
diff
changeset
|
1 from __future__ import absolute_import, print_function |
28736
403b0a7ab410
tests: lexicographical imports in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28730
diff
changeset
|
2 import os |
403b0a7ab410
tests: lexicographical imports in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28730
diff
changeset
|
3 import sys |
28729
fc2268b9a07c
py3: use absolute_import in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
23308
diff
changeset
|
4 import unittest |
18665
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
5 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28736
diff
changeset
|
6 |
18665
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 def main(modulename): |
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
8 '''run the tests found in module, printing nothing when all tests pass''' |
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
9 module = sys.modules[modulename] |
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
10 suite = unittest.defaultTestLoader.loadTestsFromModule(module) |
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
11 results = unittest.TestResult() |
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
12 suite.run(results) |
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 if results.errors or results.failures: |
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 for tc, exc in results.errors: |
28730
73437077753c
py3: use print_function in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28729
diff
changeset
|
15 print('ERROR:', tc) |
73437077753c
py3: use print_function in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28729
diff
changeset
|
16 print() |
18665
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 sys.stdout.write(exc) |
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 for tc, exc in results.failures: |
28730
73437077753c
py3: use print_function in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28729
diff
changeset
|
19 print('FAIL:', tc) |
73437077753c
py3: use print_function in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28729
diff
changeset
|
20 print() |
18665
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
21 sys.stdout.write(exc) |
2cbfb8c497ee
tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
22 sys.exit(1) |
23308
dadcd40b62d8
silenttestrunner: add environment variable to make tests noisy again
Augie Fackler <augie@google.com>
parents:
18665
diff
changeset
|
23 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28736
diff
changeset
|
24 |
23308
dadcd40b62d8
silenttestrunner: add environment variable to make tests noisy again
Augie Fackler <augie@google.com>
parents:
18665
diff
changeset
|
25 if os.environ.get('SILENT_BE_NOISY'): |
dadcd40b62d8
silenttestrunner: add environment variable to make tests noisy again
Augie Fackler <augie@google.com>
parents:
18665
diff
changeset
|
26 main = unittest.main |