test: use unittest for test_framework unit testing #18576

pull glozow wants to merge 1 commits into bitcoin:master from glozow:framework-unittests changing 3 files +39 −46
  1. glozow commented at 6:20 pm on April 9, 2020: member

    Proposal for unit testing on test_framework functions:

    1. Use the python unittest library. Don’t use test_framework to test itself.
    2. Put the tests inside the same file as the functions they are testing.
    3. Call the tests from test_runner.py. To include more Test Framework tests, add the filename to the list TEST_FRAMEWORK_MODULES. Don’t add new files or change the list of accepted script prefixes.

    Makes these changes for bn2vch (followup to this comment).

  2. DrahtBot added the label Tests on Apr 9, 2020
  3. DrahtBot commented at 9:07 pm on April 9, 2020: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    No conflicts as of last run.

  4. glozow force-pushed on Apr 10, 2020
  5. glozow force-pushed on Apr 10, 2020
  6. glozow force-pushed on Apr 10, 2020
  7. fanquake renamed this:
    wip [test] use unittest for test_framework unit testing
    [wip] test: use unittest for test_framework unit testing
    on Apr 11, 2020
  8. fanquake requested review from jnewbery on Apr 11, 2020
  9. jnewbery commented at 0:30 am on April 11, 2020: member
    Concept ACK! @sipa @MarcoFalke you may also be interested in this, since we all discussed this in #18378.
  10. glozow force-pushed on Apr 11, 2020
  11. glozow force-pushed on Apr 11, 2020
  12. glozow force-pushed on Apr 11, 2020
  13. in test/functional/test_runner.py:28 in 6cc896405e outdated
    23@@ -24,6 +24,10 @@
    24 import tempfile
    25 import re
    26 import logging
    27+import unittest
    28+import test_framework.script
    


    jnewbery commented at 8:40 pm on April 13, 2020:

    It seems a shame to have to list the modules out multiple times. If you use the loadTestsFromName() method, you can avoid having to import the modules:

    0TEST_FRAMEWORK_MODULES = [
    1    "script",
    2    "key",
    3    "messages",
    4]
    5... 
    6    # Test Framework Tests
    7    for module in TEST_FRAMEWORK_MODULES:
    8        suite = unittest.TestLoader().loadTestsFromName("test_framework.{}".format(module))
    9        unittest.TextTestRunner(verbosity=1).run(suite)
    

    If you wanted to be really clever, you could just search all the modules for which ones import unittest and then automatically pick them up in the test runner, so they don’t need to be listed out at all. I don’t think that’s necessary in this PR, but you might want to consider it in a follow-up.


    glozow commented at 2:31 am on April 21, 2020:
    Ahhh yes this is what I wanted to do! Ran into a bunch of import errors when I tried to auto discover everything, will look into it further.
  14. in test/functional/test_runner.py:399 in 6cc896405e outdated
    392@@ -384,6 +393,11 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=
    393     if os.path.isdir(cache_dir):
    394         print("%sWARNING!%s There is a cache directory here: %s. If tests fail unexpectedly, try deleting the cache directory." % (BOLD[1], BOLD[0], cache_dir))
    395 
    396+    # Test Framework Tests
    397+    for module in TEST_FRAMEWORK_MODULES:
    398+        suite = unittest.TestLoader().loadTestsFromModule(module)
    399+        unittest.TextTestRunner(verbosity=2).run(suite)
    


    jnewbery commented at 8:42 pm on April 13, 2020:
    It’d be nice if we could have less verbosity for successful unittest runs, and only have verbose output for tests that fail. Otherwise, these will take up a lot of screen space for every run.

    glozow commented at 5:27 pm on April 21, 2020:
    Good point, thank you so much for all the feedback! Verbosity=1 does the least printing, but still prints every time TestCase.run() is called, so I made it more concise by grouping all the tests into one TestSuite and calling run() just once instead of doing them each individually. These tests would probably all be very small so I figured it would be alright. On success, it’s 4 lines. On fail, it’s more verbose and quits early. Hopefully this is ok?
  15. jnewbery commented at 8:45 pm on April 13, 2020: member

    Concept and approach ACK. Thanks for tackling this, @gzhao408 .

    I left a couple of comments inline. A few more ideas:

    • Perhaps print something immediately before the unit tests to indicate what’s happening. Something like “Running test framework unit tests”.
    • The test runner should probably exit with an error state if any of the unit tests fail (to cause travis to fail immediately).
  16. jnewbery commented at 11:09 pm on April 13, 2020: member
    Here are some tips for writing great commit messages: https://chris.beams.io/posts/git-commit/. Particularly look at section 7 (why-not-how), and make sure to include a blank line between the summary and details.
  17. practicalswift commented at 3:05 pm on April 21, 2020: contributor

    Concept ACK

    Thanks for tackling this. Great initiative! :)

  18. jnewbery commented at 6:12 pm on April 21, 2020: member
    This is looking really good @gzhao408 . I recommend that in this PR you just add the unit test framework to test_runner.py and move the script tests to script.py, and then open follow-up PRs to add the key.py and messages.py tests.
  19. glozow force-pushed on Apr 21, 2020
  20. glozow renamed this:
    [wip] test: use unittest for test_framework unit testing
    test: use unittest for test_framework unit testing
    on Apr 21, 2020
  21. glozow marked this as ready for review on Apr 21, 2020
  22. glozow force-pushed on Apr 21, 2020
  23. test: use unittest and test_runner for test framework unit testing
    Test the test_framework, but don't use test_framework objects or functions to test itself
    
    Use python unittest library and put test_framework's unit tests inside their respective files
    Add the filename to TEST_FRAMEWORK_MODULES in test_runner
    Aggregate all test_framework tests into one TestSuite to run before the functional tests in test_runner
    Delete framework_test_script, move test_bn2vch to script.py and add to TEST_FRAMEWORK_MODULES in test_runner
    de8905adf2
  24. glozow force-pushed on Apr 26, 2020
  25. glozow commented at 8:34 pm on April 26, 2020: member

    Ready for Review if anyone wants to take a look :) addressed jnewbery’s comments.

    It looks like travis failed on wallet_bumpfee.py on the last push. I just passed it locally and can’t figure out why it’s failing, so I’m having it run again. Will look again in a bit…

  26. jnewbery commented at 11:55 pm on April 29, 2020: member

    Tested ACK de8905adf204c42bba810802f82b98f7b3dd26dc. Great stuff gzhao408 . Thanks for this!

    For your next PR, try to summarize the why instead of the how in your commit log. People can look at the code to see what changes you’ve made, such as which files you’ve deleted. The log should summarize and give motivation.

  27. glozow commented at 11:58 pm on April 29, 2020: member

    Thanks so much for the review @jnewbery!

    For your next PR, try to summarize the why instead of the how in your commit log. People can look at the code to see what changes you’ve made, such as which files you’ve deleted. The log should summarize and give motivation.

    Ah, gotcha! Thanks for the feedback :) will do.

  28. MarcoFalke merged this on Apr 30, 2020
  29. MarcoFalke closed this on Apr 30, 2020

  30. sidhujag referenced this in commit 945eebe383 on May 2, 2020
  31. glozow deleted the branch on May 25, 2020
  32. gillichu referenced this in commit 8a04208077 on May 27, 2020
  33. gillichu referenced this in commit 9d5dd8752a on May 27, 2020
  34. gillichu referenced this in commit 48d08c0899 on May 28, 2020
  35. gillichu referenced this in commit 74b863e51c on May 28, 2020
  36. gillichu referenced this in commit c368d241da on May 28, 2020
  37. gillichu referenced this in commit 401487d24e on May 28, 2020
  38. gillichu referenced this in commit ef4cce175b on May 31, 2020
  39. gillichu referenced this in commit 58c4a30b0d on May 31, 2020
  40. gillichu referenced this in commit 63cba4b7fe on Jun 1, 2020
  41. gillichu referenced this in commit 91c08205bc on Jun 2, 2020
  42. gillichu referenced this in commit 60927840ff on Jun 2, 2020
  43. gillichu referenced this in commit 7daffc6a90 on Jun 3, 2020
  44. laanwj referenced this in commit 39afe5b1c6 on Jun 4, 2020
  45. sidhujag referenced this in commit f5a1bed93b on Jun 4, 2020
  46. stackman27 referenced this in commit 35dc414588 on Jun 26, 2020
  47. Fabcien referenced this in commit 4e33fac0c9 on Jan 26, 2021
  48. Fabcien referenced this in commit 2a3ba49ebb on Mar 1, 2021
  49. MarcoFalke locked this on Feb 15, 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-11-21 18:12 UTC

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