Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 1 | import argparse |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 2 | import os |
Steve Dower | 08ec6d9 | 2015-10-08 11:34:07 -0700 | [diff] [blame] | 3 | import sys |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 4 | from test import support |
Hai Shi | 3ddc634 | 2020-06-30 21:46:06 +0800 | [diff] [blame] | 5 | from test.support import os_helper |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 6 | |
Victor Stinner | 3844fe5 | 2015-09-26 10:38:01 +0200 | [diff] [blame] | 7 | |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 8 | USAGE = """\ |
| 9 | python -m test [options] [test_name1 [test_name2 ...]] |
| 10 | python path/to/Lib/test/regrtest.py [options] [test_name1 [test_name2 ...]] |
| 11 | """ |
| 12 | |
| 13 | DESCRIPTION = """\ |
| 14 | Run Python regression tests. |
| 15 | |
| 16 | If no arguments or options are provided, finds all files matching |
| 17 | the pattern "test_*" in the Lib/test subdirectory and runs |
| 18 | them in alphabetical order (but see -M and -u, below, for exceptions). |
| 19 | |
| 20 | For more rigorous testing, it is useful to use the following |
| 21 | command line: |
| 22 | |
| 23 | python -E -Wd -m test [options] [test_name1 ...] |
| 24 | """ |
| 25 | |
| 26 | EPILOG = """\ |
| 27 | Additional option details: |
| 28 | |
Serhiy Storchaka | 4a7c03a | 2015-11-02 14:44:29 +0200 | [diff] [blame] | 29 | -r randomizes test execution order. You can use --randseed=int to provide an |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 30 | int seed value for the randomizer; this is useful for reproducing troublesome |
| 31 | test orders. |
| 32 | |
| 33 | -s On the first invocation of regrtest using -s, the first test file found |
| 34 | or the first test file given on the command line is run, and the name of |
| 35 | the next test is recorded in a file named pynexttest. If run from the |
| 36 | Python build directory, pynexttest is located in the 'build' subdirectory, |
| 37 | otherwise it is located in tempfile.gettempdir(). On subsequent runs, |
| 38 | the test in pynexttest is run, and the next test is written to pynexttest. |
| 39 | When the last test has been run, pynexttest is deleted. In this way it |
| 40 | is possible to single step through the test files. This is useful when |
| 41 | doing memory analysis on the Python interpreter, which process tends to |
| 42 | consume too many resources to run the full regression test non-stop. |
| 43 | |
| 44 | -S is used to continue running tests after an aborted run. It will |
| 45 | maintain the order a standard run (ie, this assumes -r is not used). |
| 46 | This is useful after the tests have prematurely stopped for some external |
| 47 | reason and you want to start running from where you left off rather |
| 48 | than starting from the beginning. |
| 49 | |
| 50 | -f reads the names of tests from the file given as f's argument, one |
| 51 | or more test names per line. Whitespace is ignored. Blank lines and |
| 52 | lines beginning with '#' are ignored. This is especially useful for |
| 53 | whittling down failures involving interactions among tests. |
| 54 | |
| 55 | -L causes the leaks(1) command to be run just before exit if it exists. |
| 56 | leaks(1) is available on Mac OS X and presumably on some other |
| 57 | FreeBSD-derived systems. |
| 58 | |
| 59 | -R runs each test several times and examines sys.gettotalrefcount() to |
| 60 | see if the test appears to be leaking references. The argument should |
| 61 | be of the form stab:run:fname where 'stab' is the number of times the |
| 62 | test is run to let gettotalrefcount settle down, 'run' is the number |
| 63 | of times further it is run and 'fname' is the name of the file the |
| 64 | reports are written to. These parameters all have defaults (5, 4 and |
| 65 | "reflog.txt" respectively), and the minimal invocation is '-R :'. |
| 66 | |
| 67 | -M runs tests that require an exorbitant amount of memory. These tests |
| 68 | typically try to ascertain containers keep working when containing more than |
| 69 | 2 billion objects, which only works on 64-bit systems. There are also some |
| 70 | tests that try to exhaust the address space of the process, which only makes |
| 71 | sense on 32-bit systems with at least 2Gb of memory. The passed-in memlimit, |
sth | 7108aab | 2018-12-31 06:41:39 +0100 | [diff] [blame] | 72 | which is a string in the form of '2.5Gb', determines how much memory the |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 73 | tests will limit themselves to (but they may go slightly over.) The number |
| 74 | shouldn't be more memory than the machine has (including swap memory). You |
| 75 | should also keep in mind that swap memory is generally much, much slower |
| 76 | than RAM, and setting memlimit to all available RAM or higher will heavily |
| 77 | tax the machine. On the other hand, it is no use running these tests with a |
| 78 | limit of less than 2.5Gb, and many require more than 20Gb. Tests that expect |
| 79 | to use more than memlimit memory will be skipped. The big-memory tests |
| 80 | generally run very, very long. |
| 81 | |
| 82 | -u is used to specify which special resource intensive tests to run, |
| 83 | such as those requiring large file support or network connectivity. |
| 84 | The argument is a comma-separated list of words indicating the |
| 85 | resources to test. Currently only the following are defined: |
| 86 | |
| 87 | all - Enable all special resources. |
| 88 | |
| 89 | none - Disable all special resources (this is the default). |
| 90 | |
| 91 | audio - Tests that use the audio device. (There are known |
| 92 | cases of broken audio drivers that can crash Python or |
| 93 | even the Linux kernel.) |
| 94 | |
| 95 | curses - Tests that use curses and will modify the terminal's |
| 96 | state and output modes. |
| 97 | |
| 98 | largefile - It is okay to run some test that may create huge |
| 99 | files. These tests can take a long time and may |
Victor Stinner | 8c663fd | 2017-11-08 14:44:44 -0800 | [diff] [blame] | 100 | consume >2 GiB of disk space temporarily. |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 101 | |
| 102 | network - It is okay to run tests that use external network |
| 103 | resource, e.g. testing SSL support for sockets. |
| 104 | |
| 105 | decimal - Test the decimal module against a large suite that |
| 106 | verifies compliance with standards. |
| 107 | |
| 108 | cpu - Used for certain CPU-heavy tests. |
| 109 | |
| 110 | subprocess Run all tests for the subprocess module. |
| 111 | |
| 112 | urlfetch - It is okay to download files required on testing. |
| 113 | |
| 114 | gui - Run tests that require a running GUI. |
| 115 | |
Alexander Belopolsky | 5d0c598 | 2016-07-22 18:47:04 -0400 | [diff] [blame] | 116 | tzdata - Run tests that require timezone data. |
| 117 | |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 118 | To enable all resources except one, use '-uall,-<resource>'. For |
| 119 | example, to run all the tests except for the gui tests, give the |
| 120 | option '-uall,-gui'. |
Victor Stinner | ef8320c | 2017-06-09 10:18:48 +0200 | [diff] [blame] | 121 | |
| 122 | --matchfile filters tests using a text file, one pattern per line. |
| 123 | Pattern examples: |
| 124 | |
| 125 | - test method: test_stat_attributes |
| 126 | - test class: FileTests |
| 127 | - test identifier: test_os.FileTests.test_stat_attributes |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 128 | """ |
| 129 | |
| 130 | |
Victor Stinner | 5b392bb | 2017-07-20 15:46:32 +0200 | [diff] [blame] | 131 | ALL_RESOURCES = ('audio', 'curses', 'largefile', 'network', |
| 132 | 'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui') |
| 133 | |
| 134 | # Other resources excluded from --use=all: |
| 135 | # |
| 136 | # - extralagefile (ex: test_zipfile64): really too slow to be enabled |
| 137 | # "by default" |
| 138 | # - tzdata: while needed to validate fully test_datetime, it makes |
| 139 | # test_datetime too slow (15-20 min on some buildbots) and so is disabled by |
| 140 | # default (see bpo-30822). |
| 141 | RESOURCE_NAMES = ALL_RESOURCES + ('extralargefile', 'tzdata') |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 142 | |
Miss Islington (bot) | 9608719 | 2021-07-22 13:30:44 -0700 | [diff] [blame^] | 143 | |
| 144 | class Namespace(argparse.Namespace): |
| 145 | def __init__(self, **kwargs) -> None: |
| 146 | self.testdir = None |
| 147 | self.verbose = 0 |
| 148 | self.quiet = False |
| 149 | self.exclude = False |
| 150 | self.single = False |
| 151 | self.randomize = False |
| 152 | self.fromfile = None |
| 153 | self.findleaks = 1 |
| 154 | self.fail_env_changed = False |
| 155 | self.use_resources = None |
| 156 | self.trace = False |
| 157 | self.coverdir = 'coverage' |
| 158 | self.runleaks = False |
| 159 | self.huntrleaks = False |
| 160 | self.verbose2 = False |
| 161 | self.verbose3 = False |
| 162 | self.print_slow = False |
| 163 | self.random_seed = None |
| 164 | self.use_mp = None |
| 165 | self.forever = False |
| 166 | self.header = False |
| 167 | self.failfast = False |
| 168 | self.match_tests = None |
| 169 | self.ignore_tests = None |
| 170 | self.pgo = False |
| 171 | self.pgo_extended = False |
| 172 | |
| 173 | super().__init__(**kwargs) |
| 174 | |
| 175 | |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 176 | class _ArgParser(argparse.ArgumentParser): |
| 177 | |
| 178 | def error(self, message): |
| 179 | super().error(message + "\nPass -h or --help for complete help.") |
| 180 | |
| 181 | |
| 182 | def _create_parser(): |
| 183 | # Set prog to prevent the uninformative "__main__.py" from displaying in |
| 184 | # error messages when using "python -m test ...". |
| 185 | parser = _ArgParser(prog='regrtest.py', |
| 186 | usage=USAGE, |
| 187 | description=DESCRIPTION, |
| 188 | epilog=EPILOG, |
| 189 | add_help=False, |
| 190 | formatter_class=argparse.RawDescriptionHelpFormatter) |
| 191 | |
| 192 | # Arguments with this clause added to its help are described further in |
| 193 | # the epilog's "Additional option details" section. |
| 194 | more_details = ' See the section at bottom for more details.' |
| 195 | |
| 196 | group = parser.add_argument_group('General options') |
| 197 | # We add help explicitly to control what argument group it renders under. |
| 198 | group.add_argument('-h', '--help', action='help', |
| 199 | help='show this help message and exit') |
| 200 | group.add_argument('--timeout', metavar='TIMEOUT', type=float, |
| 201 | help='dump the traceback and exit if a test takes ' |
| 202 | 'more than TIMEOUT seconds; disabled if TIMEOUT ' |
| 203 | 'is negative or equals to zero') |
| 204 | group.add_argument('--wait', action='store_true', |
| 205 | help='wait for user input, e.g., allow a debugger ' |
| 206 | 'to be attached') |
Victor Stinner | 012f5b9 | 2018-09-07 17:20:42 +0200 | [diff] [blame] | 207 | group.add_argument('--worker-args', metavar='ARGS') |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 208 | group.add_argument('-S', '--start', metavar='START', |
| 209 | help='the name of the test at which to start.' + |
| 210 | more_details) |
| 211 | |
| 212 | group = parser.add_argument_group('Verbosity') |
| 213 | group.add_argument('-v', '--verbose', action='count', |
| 214 | help='run tests in verbose mode with output to stdout') |
| 215 | group.add_argument('-w', '--verbose2', action='store_true', |
| 216 | help='re-run failed tests in verbose mode') |
| 217 | group.add_argument('-W', '--verbose3', action='store_true', |
| 218 | help='display test output on failure') |
| 219 | group.add_argument('-q', '--quiet', action='store_true', |
| 220 | help='no output unless one or more tests fail') |
Victor Stinner | 6c44619 | 2016-08-17 11:25:43 +0200 | [diff] [blame] | 221 | group.add_argument('-o', '--slowest', action='store_true', dest='print_slow', |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 222 | help='print the slowest 10 tests') |
| 223 | group.add_argument('--header', action='store_true', |
| 224 | help='print header with interpreter info') |
| 225 | |
| 226 | group = parser.add_argument_group('Selecting tests') |
| 227 | group.add_argument('-r', '--randomize', action='store_true', |
| 228 | help='randomize test execution order.' + more_details) |
| 229 | group.add_argument('--randseed', metavar='SEED', |
| 230 | dest='random_seed', type=int, |
| 231 | help='pass a random seed to reproduce a previous ' |
| 232 | 'random run') |
| 233 | group.add_argument('-f', '--fromfile', metavar='FILE', |
| 234 | help='read names of tests to run from a file.' + |
| 235 | more_details) |
| 236 | group.add_argument('-x', '--exclude', action='store_true', |
| 237 | help='arguments are tests to *exclude*') |
| 238 | group.add_argument('-s', '--single', action='store_true', |
| 239 | help='single step through a set of tests.' + |
| 240 | more_details) |
| 241 | group.add_argument('-m', '--match', metavar='PAT', |
Victor Stinner | ef8320c | 2017-06-09 10:18:48 +0200 | [diff] [blame] | 242 | dest='match_tests', action='append', |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 243 | help='match test cases and methods with glob pattern PAT') |
Pablo Galindo | e0cd8aa | 2019-11-19 23:46:49 +0000 | [diff] [blame] | 244 | group.add_argument('-i', '--ignore', metavar='PAT', |
| 245 | dest='ignore_tests', action='append', |
| 246 | help='ignore test cases and methods with glob pattern PAT') |
Victor Stinner | ef8320c | 2017-06-09 10:18:48 +0200 | [diff] [blame] | 247 | group.add_argument('--matchfile', metavar='FILENAME', |
| 248 | dest='match_filename', |
| 249 | help='similar to --match but get patterns from a ' |
| 250 | 'text file, one pattern per line') |
Pablo Galindo | e0cd8aa | 2019-11-19 23:46:49 +0000 | [diff] [blame] | 251 | group.add_argument('--ignorefile', metavar='FILENAME', |
| 252 | dest='ignore_filename', |
| 253 | help='similar to --matchfile but it receives patterns ' |
| 254 | 'from text file to ignore') |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 255 | group.add_argument('-G', '--failfast', action='store_true', |
| 256 | help='fail as soon as a test fails (only with -v or -W)') |
| 257 | group.add_argument('-u', '--use', metavar='RES1,RES2,...', |
| 258 | action='append', type=resources_list, |
| 259 | help='specify which special resource intensive tests ' |
| 260 | 'to run.' + more_details) |
| 261 | group.add_argument('-M', '--memlimit', metavar='LIMIT', |
| 262 | help='run very large memory-consuming tests.' + |
| 263 | more_details) |
| 264 | group.add_argument('--testdir', metavar='DIR', |
| 265 | type=relative_filename, |
| 266 | help='execute test files in the specified directory ' |
| 267 | '(instead of the Python stdlib test suite)') |
| 268 | |
| 269 | group = parser.add_argument_group('Special runs') |
Victor Stinner | 75120d2 | 2019-04-26 09:28:53 +0200 | [diff] [blame] | 270 | group.add_argument('-l', '--findleaks', action='store_const', const=2, |
| 271 | default=1, |
| 272 | help='deprecated alias to --fail-env-changed') |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 273 | group.add_argument('-L', '--runleaks', action='store_true', |
| 274 | help='run the leaks(1) command just before exit.' + |
| 275 | more_details) |
| 276 | group.add_argument('-R', '--huntrleaks', metavar='RUNCOUNTS', |
| 277 | type=huntrleaks, |
| 278 | help='search for reference leaks (needs debug build, ' |
| 279 | 'very slow).' + more_details) |
| 280 | group.add_argument('-j', '--multiprocess', metavar='PROCESSES', |
| 281 | dest='use_mp', type=int, |
| 282 | help='run PROCESSES processes at once') |
| 283 | group.add_argument('-T', '--coverage', action='store_true', |
| 284 | dest='trace', |
| 285 | help='turn on code coverage tracing using the trace ' |
| 286 | 'module') |
| 287 | group.add_argument('-D', '--coverdir', metavar='DIR', |
| 288 | type=relative_filename, |
| 289 | help='directory where coverage files are put') |
| 290 | group.add_argument('-N', '--nocoverdir', |
| 291 | action='store_const', const=None, dest='coverdir', |
| 292 | help='put coverage files alongside modules') |
| 293 | group.add_argument('-t', '--threshold', metavar='THRESHOLD', |
| 294 | type=int, |
| 295 | help='call gc.set_threshold(THRESHOLD)') |
| 296 | group.add_argument('-n', '--nowindows', action='store_true', |
| 297 | help='suppress error message boxes on Windows') |
| 298 | group.add_argument('-F', '--forever', action='store_true', |
| 299 | help='run the specified tests in a loop, until an ' |
Victor Stinner | b0917df | 2019-05-13 19:17:54 +0200 | [diff] [blame] | 300 | 'error happens; imply --failfast') |
Victor Stinner | 5f9d3ac | 2015-10-03 00:21:12 +0200 | [diff] [blame] | 301 | group.add_argument('--list-tests', action='store_true', |
| 302 | help="only write the name of tests that will be run, " |
| 303 | "don't execute them") |
mlouielu | a49c935 | 2017-06-16 17:36:19 +0800 | [diff] [blame] | 304 | group.add_argument('--list-cases', action='store_true', |
| 305 | help='only write the name of test cases that will be run' |
| 306 | ' , don\'t execute them') |
Brett Cannon | 11faa21 | 2015-10-02 16:20:49 -0700 | [diff] [blame] | 307 | group.add_argument('-P', '--pgo', dest='pgo', action='store_true', |
Neil Schemenauer | 4e16a4a | 2019-07-22 12:54:25 -0700 | [diff] [blame] | 308 | help='enable Profile Guided Optimization (PGO) training') |
| 309 | group.add_argument('--pgo-extended', action='store_true', |
| 310 | help='enable extended PGO training (slower training)') |
Victor Stinner | 63f54c6 | 2017-06-26 18:33:19 +0200 | [diff] [blame] | 311 | group.add_argument('--fail-env-changed', action='store_true', |
| 312 | help='if a test file alters the environment, mark ' |
| 313 | 'the test as failed') |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 314 | |
Steve Dower | d0f49d2 | 2018-09-18 09:10:26 -0700 | [diff] [blame] | 315 | group.add_argument('--junit-xml', dest='xmlpath', metavar='FILENAME', |
| 316 | help='writes JUnit-style XML results to the specified ' |
| 317 | 'file') |
Victor Stinner | 47fbc4e | 2019-06-24 12:03:00 +0200 | [diff] [blame] | 318 | group.add_argument('--tempdir', metavar='PATH', |
Steve Dower | 38df97a | 2018-11-17 04:14:36 -0800 | [diff] [blame] | 319 | help='override the working directory for the test run') |
Victor Stinner | 47fbc4e | 2019-06-24 12:03:00 +0200 | [diff] [blame] | 320 | group.add_argument('--cleanup', action='store_true', |
| 321 | help='remove old test_python_* directories') |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 322 | return parser |
| 323 | |
| 324 | |
| 325 | def relative_filename(string): |
| 326 | # CWD is replaced with a temporary dir before calling main(), so we |
| 327 | # join it with the saved CWD so it ends up where the user expects. |
Hai Shi | 3ddc634 | 2020-06-30 21:46:06 +0800 | [diff] [blame] | 328 | return os.path.join(os_helper.SAVEDCWD, string) |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 329 | |
| 330 | |
| 331 | def huntrleaks(string): |
| 332 | args = string.split(':') |
| 333 | if len(args) not in (2, 3): |
| 334 | raise argparse.ArgumentTypeError( |
| 335 | 'needs 2 or 3 colon-separated arguments') |
| 336 | nwarmup = int(args[0]) if args[0] else 5 |
| 337 | ntracked = int(args[1]) if args[1] else 4 |
| 338 | fname = args[2] if len(args) > 2 and args[2] else 'reflog.txt' |
| 339 | return nwarmup, ntracked, fname |
| 340 | |
| 341 | |
| 342 | def resources_list(string): |
| 343 | u = [x.lower() for x in string.split(',')] |
| 344 | for r in u: |
| 345 | if r == 'all' or r == 'none': |
| 346 | continue |
| 347 | if r[0] == '-': |
| 348 | r = r[1:] |
| 349 | if r not in RESOURCE_NAMES: |
| 350 | raise argparse.ArgumentTypeError('invalid resource: ' + r) |
| 351 | return u |
| 352 | |
| 353 | |
| 354 | def _parse_args(args, **kwargs): |
| 355 | # Defaults |
Miss Islington (bot) | 9608719 | 2021-07-22 13:30:44 -0700 | [diff] [blame^] | 356 | ns = Namespace() |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 357 | for k, v in kwargs.items(): |
| 358 | if not hasattr(ns, k): |
| 359 | raise TypeError('%r is an invalid keyword argument ' |
| 360 | 'for this function' % k) |
| 361 | setattr(ns, k, v) |
| 362 | if ns.use_resources is None: |
| 363 | ns.use_resources = [] |
| 364 | |
| 365 | parser = _create_parser() |
Victor Stinner | a506a93 | 2016-10-17 18:13:46 +0200 | [diff] [blame] | 366 | # Issue #14191: argparse doesn't support "intermixed" positional and |
| 367 | # optional arguments. Use parse_known_args() as workaround. |
| 368 | ns.args = parser.parse_known_args(args=args, namespace=ns)[1] |
| 369 | for arg in ns.args: |
| 370 | if arg.startswith('-'): |
| 371 | parser.error("unrecognized arguments: %s" % arg) |
| 372 | sys.exit(1) |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 373 | |
Victor Stinner | 75120d2 | 2019-04-26 09:28:53 +0200 | [diff] [blame] | 374 | if ns.findleaks > 1: |
| 375 | # --findleaks implies --fail-env-changed |
| 376 | ns.fail_env_changed = True |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 377 | if ns.single and ns.fromfile: |
| 378 | parser.error("-s and -f don't go together!") |
Xiang Zhang | 772bf2e | 2016-12-19 22:00:22 +0800 | [diff] [blame] | 379 | if ns.use_mp is not None and ns.trace: |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 380 | parser.error("-T and -j don't go together!") |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 381 | if ns.failfast and not (ns.verbose or ns.verbose3): |
| 382 | parser.error("-G/--failfast needs either -v or -W") |
Brett Cannon | 11faa21 | 2015-10-02 16:20:49 -0700 | [diff] [blame] | 383 | if ns.pgo and (ns.verbose or ns.verbose2 or ns.verbose3): |
| 384 | parser.error("--pgo/-v don't go together!") |
Neil Schemenauer | 4e16a4a | 2019-07-22 12:54:25 -0700 | [diff] [blame] | 385 | if ns.pgo_extended: |
| 386 | ns.pgo = True # pgo_extended implies pgo |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 387 | |
Steve Dower | 12c2945 | 2015-10-08 09:05:36 -0700 | [diff] [blame] | 388 | if ns.nowindows: |
| 389 | print("Warning: the --nowindows (-n) option is deprecated. " |
| 390 | "Use -vv to display assertions in stderr.", file=sys.stderr) |
| 391 | |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 392 | if ns.quiet: |
| 393 | ns.verbose = 0 |
| 394 | if ns.timeout is not None: |
Victor Stinner | 5f9d3ac | 2015-10-03 00:21:12 +0200 | [diff] [blame] | 395 | if ns.timeout <= 0: |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 396 | ns.timeout = None |
| 397 | if ns.use_mp is not None: |
| 398 | if ns.use_mp <= 0: |
| 399 | # Use all cores + extras for tests that like to sleep |
| 400 | ns.use_mp = 2 + (os.cpu_count() or 1) |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 401 | if ns.use: |
| 402 | for a in ns.use: |
| 403 | for r in a: |
| 404 | if r == 'all': |
Victor Stinner | 5b392bb | 2017-07-20 15:46:32 +0200 | [diff] [blame] | 405 | ns.use_resources[:] = ALL_RESOURCES |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 406 | continue |
| 407 | if r == 'none': |
| 408 | del ns.use_resources[:] |
| 409 | continue |
| 410 | remove = False |
| 411 | if r[0] == '-': |
| 412 | remove = True |
| 413 | r = r[1:] |
| 414 | if remove: |
| 415 | if r in ns.use_resources: |
| 416 | ns.use_resources.remove(r) |
| 417 | elif r not in ns.use_resources: |
| 418 | ns.use_resources.append(r) |
| 419 | if ns.random_seed is not None: |
| 420 | ns.randomize = True |
Victor Stinner | 3d00568 | 2017-05-04 15:21:12 +0200 | [diff] [blame] | 421 | if ns.verbose: |
| 422 | ns.header = True |
Victor Stinner | fcdd9b6 | 2017-05-18 13:03:24 -0700 | [diff] [blame] | 423 | if ns.huntrleaks and ns.verbose3: |
| 424 | ns.verbose3 = False |
| 425 | print("WARNING: Disable --verbose3 because it's incompatible with " |
| 426 | "--huntrleaks: see http://bugs.python.org/issue27103", |
| 427 | file=sys.stderr) |
Victor Stinner | ef8320c | 2017-06-09 10:18:48 +0200 | [diff] [blame] | 428 | if ns.match_filename: |
| 429 | if ns.match_tests is None: |
| 430 | ns.match_tests = [] |
Steve Dower | 38df97a | 2018-11-17 04:14:36 -0800 | [diff] [blame] | 431 | with open(ns.match_filename) as fp: |
Victor Stinner | ef8320c | 2017-06-09 10:18:48 +0200 | [diff] [blame] | 432 | for line in fp: |
| 433 | ns.match_tests.append(line.strip()) |
Pablo Galindo | e0cd8aa | 2019-11-19 23:46:49 +0000 | [diff] [blame] | 434 | if ns.ignore_filename: |
| 435 | if ns.ignore_tests is None: |
| 436 | ns.ignore_tests = [] |
| 437 | with open(ns.ignore_filename) as fp: |
| 438 | for line in fp: |
| 439 | ns.ignore_tests.append(line.strip()) |
Victor Stinner | b0917df | 2019-05-13 19:17:54 +0200 | [diff] [blame] | 440 | if ns.forever: |
| 441 | # --forever implies --failfast |
| 442 | ns.failfast = True |
Victor Stinner | 98de534 | 2015-09-26 09:43:45 +0200 | [diff] [blame] | 443 | |
| 444 | return ns |