Page MenuHomePhabricator

[electrum] let unittest discover all test cases
ClosedPublic

Authored by PiRK on Sep 1 2023, 14:29.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC57176a00e4d6: [electrum] let unittest discover all test cases
Summary

This does not change the behavior of the test_runner.py script which was already discovering the tests.

It fixes running the test suites individually when the suite() function was not maintained, e.g.:

python -m electrumabc.tests.test_wallet

From the unitest.main doc:

The defaultTest argument is either the name of a single test or an iterable of test names to run if no test names are specified via argv. If not specified or None and no test names are provided via argv, all tests found in module are run.

Depends on D14442

Test Plan
python test_runner.py
python -m electrumabc.tests.test_wallet
python -m electrumabc.tests.test_transaction

Check that all test cases are run (same number of tests before and after this change in the case of test_runner.py).

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Sep 1 2023, 14:29

so each unit defaults to a suite named after the file ?

so each unit defaults to a suite named after the file ?

No, it defaults to discovering all TestCases .

When I want to run a single file I'm just running the module directly with python -m, so it ends up running the if __name__ == "__main__" block, and unitest.main() discover all the tests in the module by default (previously it was only running the test suite called suite, which in this case was a function returning a TestSuite)

https://docs.python.org/3/using/cmdline.html#cmdoption-m (this works because the current working directory is on the python path https://docs.python.org/3/library/sys_path_init.html)

https://docs.python.org/3/library/unittest.html#unittest.main

This revision is now accepted and ready to land.Sep 3 2023, 05:46