tests: Use colors and dots in test_runner.py output only if standard output is a terminal #16561

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:parsable changing 1 files +18 −5
  1. practicalswift commented at 11:21 am on August 7, 2019: contributor

    Use colors and dots in test_runner.py output only if standard output is a terminal – allows for using the test runner output as input to other programs.

    I found the need for this when parsing test_runner.py output while investigating intermittent functional test failures.

    Before:

     0$ test/functional/test_runner.py wallet_hd.py > output 2>&1
     1$ less output
     2Temporary test directory at /tmp/test_runner_₿_🏃_20190807_074115
     3ESC[1mWARNING!ESC[0m There is already a bitcoind process running on this system. Tests may fail unexpectedly due to resource contention!
     4Remaining jobs: [wallet_hd.py]
     5.......................................^M                                       ^M1/1 - ESC[1mwallet_hd.pyESC[0m passed, Duration: 20 s
     6
     7ESC[1mTEST         | STATUS    | DURATION
     8
     9ESC[0mESC[0;32mwallet_hd.py | ✓ Passed  | 20 s
    10ESC[0mESC[1m
    11ALL          | ✓ Passed  | 20 s (accumulated)
    12ESC[0mRuntime: 20 s
    

    After:

     0$ test/functional/test_runner.py wallet_hd.py > output 2>&1
     1$ less output
     2Temporary test directory at /tmp/test_runner_₿_🏃_20190807_074244
     31/1 - wallet_hd.py passed, Duration: 20 s
     4WARNING! There is already a bitcoind process running on this system. Tests may fail unexpectedly due to resource contention!
     5Remaining jobs: [wallet_hd.py]
     6
     7TEST         | STATUS    | DURATION
     8
     9wallet_hd.py | ✓ Passed  | 20 s
    10
    11ALL          | ✓ Passed  | 20 s (accumulated)
    12Runtime: 20 s
    
  2. fanquake added the label Tests on Aug 7, 2019
  3. promag commented at 11:36 pm on August 7, 2019: member
    Could use sys.stdout.isatty() to automatically disable colors and progress dots?
  4. practicalswift commented at 6:10 am on August 8, 2019: contributor
    @promag Good point – I thought about that but I’m not sure sys.stdout.isatty() holds True in Travis where we want the dots at least. I’ll investigate :-)
  5. fanquake requested review from MarcoFalke on Aug 12, 2019
  6. MarcoFalke added the label Waiting for author on Aug 12, 2019
  7. practicalswift force-pushed on Aug 15, 2019
  8. practicalswift force-pushed on Aug 15, 2019
  9. practicalswift renamed this:
    tests: Add test_runner.py option --parsable
    tests: Use colors and dots in test_runner.py output only if standard output is a terminal
    on Aug 15, 2019
  10. practicalswift commented at 8:31 am on August 15, 2019: contributor
    @promag Turns out sys.stdout.isatty() holds True also in Travis. Updated PR. Would you mind re-reviewing? :-)
  11. tests: Use colors and dots in test_runner.py output only if standard output is a terminal -- allows for using the test runner output as input to other programs 37f2784952
  12. in test/functional/test_runner.py:59 in 6ac121bac3 outdated
    60-    # terminal via ANSI escape sequences:
    61-    BOLD = ('\033[0m', '\033[1m')
    62-    GREEN = ('\033[0m', '\033[0;32m')
    63-    RED = ('\033[0m', '\033[0;31m')
    64-    GREY = ('\033[0m', '\033[1;30m')
    65+    if sys.stdout.isatty():
    


    laanwj commented at 9:24 am on August 15, 2019:
    please call the sys.stdout.isatty() only once and assign it to a variable (use_term_control or something like that) if you use it later I’d like to add an argument to override this, there are cases where one might want to redirect the output to something that doesn’t identify as a tty but still supports terminal control sequences (e.g. when calling the tests over SSH)

    promag commented at 9:53 am on August 15, 2019:
    Yeah my suggestion was to use isatty value as the option default value.

    practicalswift commented at 9:55 am on August 15, 2019:
    Good points. Now addressed. Please re-review :-)
  13. practicalswift force-pushed on Aug 15, 2019
  14. laanwj commented at 10:42 am on August 15, 2019: member
    Looks good to me now, ACK 37f2784952cb6f598f82922f9ce71d40c9d74e26
  15. MarcoFalke merged this on Aug 15, 2019
  16. MarcoFalke closed this on Aug 15, 2019

  17. MarcoFalke referenced this in commit e00501e00c on Aug 15, 2019
  18. MarcoFalke referenced this in commit aed15edf17 on Aug 16, 2019
  19. laanwj removed the label Waiting for author on Oct 24, 2019
  20. practicalswift deleted the branch on Apr 10, 2021
  21. DrahtBot locked this on Aug 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-06 01:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me