Changeset 92cf138 in mod_gnutls for test/runtest.py


Ignore:
Timestamp:
Dec 31, 2019, 11:37:18 AM (19 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
asyncio, master, proxy-ticket
Children:
4de8cd3
Parents:
b457e67
Message:

runtest.py: Provide temporary log files by default

This means tests don't need to set log file parameters just for their
hooks, and also simplifies the code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/runtest.py

    rb457e67 r92cf138  
    2121import subprocess
    2222import sys
     23import tempfile
    2324
    2425import mgstest.hooks
     
    5556            return (found.path, found.name)
    5657
     58def temp_logfile():
     59    return tempfile.SpooledTemporaryFile(max_size=4096, mode='w+',
     60                                         prefix='mod_gnutls', suffix=".log")
     61
     62
    5763
    5864
     
    187193    # run extra checks the test's hooks.py might define
    188194    if plugin.post_check:
    189         if args.log_connection:
    190             args.log_connection.seek(0)
    191         if args.log_responses:
    192             args.log_responses.seek(0)
     195        args.log_connection.seek(0)
     196        args.log_responses.seek(0)
    193197        plugin.post_check(conn_log=args.log_connection,
    194198                          response_log=args.log_responses)
     
    202206    parser.add_argument('--test-number', type=int,
    203207                        required=True, help='load YAML test configuration')
    204     # TODO: The log files should be created as temporary
    205     # files if needed by the plugin but not configured.
    206208    parser.add_argument('--log-connection', type=argparse.FileType('w+'),
    207                         default=None,
     209                        default=temp_logfile(),
    208210                        help='write connection log to this file')
    209211    parser.add_argument('--log-responses', type=argparse.FileType('w+'),
    210                         default=None,
     212                        default=temp_logfile(),
    211213                        help='write HTTP responses to this file')
    212214
     
    221223
    222224    with contextlib.ExitStack() as stack:
    223         if args.log_connection:
    224             stack.enter_context(contextlib.closing(args.log_connection))
    225         if args.log_responses:
    226             stack.enter_context(contextlib.closing(args.log_responses))
     225        stack.enter_context(contextlib.closing(args.log_connection))
     226        stack.enter_context(contextlib.closing(args.log_responses))
    227227        main(args)
Note: See TracChangeset for help on using the changeset viewer.