HomePhabricator

use f-string in test_runner.py

Description

use f-string in test_runner.py

Summary:
Also add a bold(text) function to avoid repeating the f"{BOLD[1]}...{BOLD[0]}" pattern 18 times.
Add a few variables (testname, formatted_bad_script_names, ...) to make string formatting more readable.

Depends on D13209

Test Plan:
Run ninja check-functional. Make sure the output is formatted correctly (bold test names, succesful tests in green, skipped tests in gray, checkmarks and other glyphs shown as expected, running jobs)

Add assert False to a test, run it and inspect the formatting of the error message. Then run combine_logs.py and inspect the log format.

Add a test file whith a name not following convention, and check the error message:

$ touch ../test/functional/p3p_dummy.py
$ ninja check-functional
[9/10] Running functional tests
Starting Bitcoin ABC functional tests
Temporary test directory at /home/pierre/dev/bitcoin-abc/build/test/tmp/test_runner_₿₵_🏃_20230301_121404
INFO: 16 tests not meeting naming conventions (expected 15):
  abc-cmdline.py
  abc-get-invalid-block.py
  abc-invalid-chains.py
  abc-invalid-message.py
  abc-magnetic-anomaly-mining.py
  abc-mempool-coherence-on-activations.py
  abc-minimaldata.py
  abc-parkedchain.py
  abc-replay-protection.py
  abc-schnorr.py
  abc-schnorrmultisig.py
  abc-segwit-recovery.py
  abc-sync-chain.py
  abc-transaction-ordering.py
  abc-version-message.py
  p3p_dummy.py
Traceback (most recent call last):
  File "/home/pierre/dev/bitcoin-abc/build/test/./functional/test_runner.py", line 936, in <module>
    main()
  File "/home/pierre/dev/bitcoin-abc/build/test/./functional/test_runner.py", line 364, in main
    check_script_prefixes(all_scripts)
  File "/home/pierre/dev/bitcoin-abc/build/test/./functional/test_runner.py", line 731, in check_script_prefixes
    assert \
AssertionError: Too many tests not following naming convention! (16 found, expected: <= 15)
$ rm ../test/functional/p3p_dummy.py
rm: remove regular empty file '../test/functional/p3p_dummy.py'? y

Fix one of the naming convention violation, check the expected message:

$ mv ../test/functional/abc-cmdline.py  ../test/functional/abc_feature_cmdline.py
$ ninja check-functional
...
[2/3] Running functional tests
Starting Bitcoin ABC functional tests
Temporary test directory at /home/pierre/dev/bitcoin-abc/build/test/tmp/test_runner_₿₵_🏃_20230301_122256
HURRAY!! Number of functional tests violating naming convention reduced!
Consider reducing EXPECTED_VIOLATION_COUNT from 15 to 14
Running Unit Tests for Test Framework Modules
...

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13210

Details

Provenance
PiRKAuthored on Mar 1 2023, 10:52
PiRKPushed on Mar 1 2023, 13:03
Reviewer
Restricted Project
Differential Revision
D13210: use f-string in test_runner.py
Parents
rABC29fa685df764: use f-strings in functional tests (long lines)
Branches
Unknown
Tags
Unknown