annotate tests/run.py @ 1517:b3e41b0d50a2

test: enable devel.all-warnings This enables some extra checks in core Mercurial helpful for detecting potential issues.
author Jun Wu <quark@fb.com>
date Mon, 07 Aug 2017 18:11:56 -0700
parents dcf9eff9b5b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1052
025de18d652b tests: make our test runner executable
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1047
diff changeset
1 #!/usr/bin/env python
025de18d652b tests: make our test runner executable
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1047
diff changeset
2
610
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
3 import optparse
16
48a44546c12f Add a basic system for running the hgsubversion tests (although not the svnwrap ones) without requiring Nose. Nose is still the recommended way to run the tests.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4 import os
48a44546c12f Add a basic system for running the hgsubversion tests (although not the svnwrap ones) without requiring Nose. Nose is still the recommended way to run the tests.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 import sys
1458
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
6 import unittest
394
d70c8e45cb9e tests: add -A option to run.py for running comprehensive tests
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 393
diff changeset
7
16
48a44546c12f Add a basic system for running the hgsubversion tests (although not the svnwrap ones) without requiring Nose. Nose is still the recommended way to run the tests.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 if __name__ == '__main__':
610
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
9 description = ("This script runs the hgsubversion tests. If no tests are "
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
10 "specified, all known tests are implied.")
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
11 parser = optparse.OptionParser(usage="%prog [options] [TESTS ...]",
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
12 description=description)
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
13 parser.add_option("-A", "--all",
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
14 dest="comprehensive", action="store_true", default=False,
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
15 help="include slow, but comprehensive tests")
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
16 parser.add_option("-v", "--verbose",
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
17 dest="verbose", action="store_true", default=False,
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
18 help="enable verbose output")
614
4f6017ba4d3d testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 613
diff changeset
19 parser.add_option("", "--no-demandimport",
4f6017ba4d3d testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 613
diff changeset
20 dest="demandimport", action="store_false", default=True,
4f6017ba4d3d testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 613
diff changeset
21 help="disable Mercurial demandimport loading")
682
52fbb272a147 tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 653
diff changeset
22 parser.add_option("", "--bindings",
52fbb272a147 tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 653
diff changeset
23 dest="bindings", action="store", default=None,
52fbb272a147 tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 653
diff changeset
24 choices=["swig", "subvertpy"],
52fbb272a147 tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 653
diff changeset
25 help="test using the specified bindings (swig or "
52fbb272a147 tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 653
diff changeset
26 "subvertpy)")
688
073132fc27f1 tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 684
diff changeset
27 parser.add_option("", "--show-stdout",
073132fc27f1 tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 684
diff changeset
28 dest="showstdout", action="store_true", default=False,
073132fc27f1 tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 684
diff changeset
29 help="show stdout (hidden by default)")
357
d19843ac13c9 Allow passing in module arguments to the test runs.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 347
diff changeset
30
610
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
31 (options, args) = parser.parse_args()
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
32
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
33 if options.verbose:
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
34 testargs = { 'descriptions': 3, 'verbosity': 2 }
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
35 else:
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
36 testargs = {'descriptions': 2}
303
f423a8780832 Minor tweaks to how the tests are run.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 174
diff changeset
37
615
edd112855189 tests/run.py: make sure our hgsubversion loads correctly
Augie Fackler <durin42@gmail.com>
parents: 614
diff changeset
38 sys.path.append(os.path.dirname(os.path.dirname(__file__)))
edd112855189 tests/run.py: make sure our hgsubversion loads correctly
Augie Fackler <durin42@gmail.com>
parents: 614
diff changeset
39
614
4f6017ba4d3d testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 613
diff changeset
40 if options.demandimport:
4f6017ba4d3d testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 613
diff changeset
41 from mercurial import demandimport
4f6017ba4d3d testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 613
diff changeset
42 demandimport.enable()
4f6017ba4d3d testrunner: use demandimport, with an option to disable it
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 613
diff changeset
43
682
52fbb272a147 tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 653
diff changeset
44 if options.bindings:
697
e9306b23d323 testrunner: don't use os.putenv(), as it may not affect os.environ.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 688
diff changeset
45 os.environ['HGSUBVERSION_BINDINGS'] = options.bindings
682
52fbb272a147 tests: add an option to the test-runner for selecting bindings.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 653
diff changeset
46
644
95abc4cfc78f tests: improve import logic
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 629
diff changeset
47 # make sure our copy of hgsubversion gets imported by loading test_util
95abc4cfc78f tests: improve import logic
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 629
diff changeset
48 import test_util
95abc4cfc78f tests: improve import logic
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 629
diff changeset
49 test_util.TestBase
95abc4cfc78f tests: improve import logic
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 629
diff changeset
50
338
47c0110046dc tests: silence tests when using run.py
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
51 # silence output when running outside nose
688
073132fc27f1 tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 684
diff changeset
52 if not options.showstdout:
073132fc27f1 tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 684
diff changeset
53 import tempfile
073132fc27f1 tests: add --show-stdout option to run.py
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 684
diff changeset
54 sys.stdout = tempfile.TemporaryFile()
338
47c0110046dc tests: silence tests when using run.py
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
55
1452
4217a050a088 tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1052
diff changeset
56 args = [os.path.basename(os.path.splitext(arg)[0]).replace('-', '_')
4217a050a088 tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1052
diff changeset
57 for arg in args]
357
d19843ac13c9 Allow passing in module arguments to the test runs.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 347
diff changeset
58
1043
69a9fb45cad5 tests: consolidate all test-loading into the test runner
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1042
diff changeset
59 loader = unittest.TestLoader()
69a9fb45cad5 tests: consolidate all test-loading into the test runner
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1042
diff changeset
60 suite = unittest.TestSuite()
69a9fb45cad5 tests: consolidate all test-loading into the test runner
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1042
diff changeset
61
1458
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
62 if sys.version_info[:2] < (2, 7):
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
63 import glob
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
64 def discover(start_dir, pattern='test*.py', top_level_dir=None):
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
65 tests = []
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
66 sys.path.append(start_dir)
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
67 for path in glob.glob(os.path.join(start_dir, pattern)):
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
68 name = os.path.splitext(os.path.basename(path))[0]
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
69 tests.append(loader.loadTestsFromModule(__import__(name)))
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
70 return tests
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
71 loader.discover = discover
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
72
357
d19843ac13c9 Allow passing in module arguments to the test runs.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 347
diff changeset
73 if not args:
1458
dcf9eff9b5b7 tests: drop unittest2
Jun Wu <quark@fb.com>
parents: 1452
diff changeset
74 suite.addTests(loader.discover('.'))
1452
4217a050a088 tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1052
diff changeset
75
4217a050a088 tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1052
diff changeset
76 if options.comprehensive:
4217a050a088 tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1052
diff changeset
77 suite.addTests(loader.discover('comprehensive',
4217a050a088 tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1052
diff changeset
78 top_level_dir='comprehensive'))
357
d19843ac13c9 Allow passing in module arguments to the test runs.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 347
diff changeset
79 else:
1452
4217a050a088 tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1052
diff changeset
80 sys.path.append(os.path.join(os.path.dirname(__file__), 'comprehensive'))
4217a050a088 tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1052
diff changeset
81
4217a050a088 tests: drop hard-coded list of tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1052
diff changeset
82 suite.addTests(loader.loadTestsFromNames(args))
357
d19843ac13c9 Allow passing in module arguments to the test runs.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 347
diff changeset
83
610
300b917d23c5 testrunner: use optparse
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
84 runner = unittest.TextTestRunner(**testargs)
1043
69a9fb45cad5 tests: consolidate all test-loading into the test runner
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 1042
diff changeset
85 result = runner.run(suite)
571
f3e5ef8760cb tests.run: exit nonzero if tests did not pass
Augie Fackler <durin42@gmail.com>
parents: 426
diff changeset
86 if not result.wasSuccessful():
f3e5ef8760cb tests.run: exit nonzero if tests did not pass
Augie Fackler <durin42@gmail.com>
parents: 426
diff changeset
87 sys.exit(1)