Page MenuHomePhabricator

use f-string in test_runner.py
ClosedPublic

Authored by PiRK on Mar 1 2023, 11:27.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCb5117ee62113: 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
...

Diff Detail

Event Timeline

PiRK requested review of this revision.Mar 1 2023, 11:27
Fabien added a subscriber: Fabien.
Fabien added inline comments.
test/functional/test_runner.py
608
This revision is now accepted and ready to land.Mar 1 2023, 12:36

review + replace .ljust(max_len_name) by the relevant string formatting magic {...:<{max_len_name}} on the same line

Fix a display bug in bold()

This revision was landed with ongoing or failed builds.Mar 1 2023, 13:03
This revision was automatically updated to reflect the committed changes.