Tests: Add Metaclass for BitcoinTestFramework #12856

pull WillAyd wants to merge 1 commits into bitcoin:master from WillAyd:meta-tst changing 1 files +23 −1
  1. WillAyd commented at 6:01 AM on April 2, 2018: contributor

    BitcoinTestFramework instructs developers in its docstring to override set_test_params and run_test in subclasses while being sure NOT to override __init__ and main . This change adds a metaclass to ensure that developers adhere to that protocol, raising a TypeError in instances where they have not.

    closes #12835

  2. in test/functional/test_framework/test_base.py:80 in f68e6b4b3f outdated
      75 | +    def test_exempts_framework_class(self):
      76 | +        class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
      77 | +            pass
      78 | +
      79 | +if __name__ == '__main__':
      80 | +    unittest.main()
    


    WillAyd commented at 6:04 AM on April 2, 2018:

    As is this is not integrated into your current CI. Still trying to wrap my head around everything so I could be wrong on this but since you are using your own test suite / runner which uses this meta class I don't think there's a great way to integrate into your current workflow. This can be tested directly from the command line as needed

  3. in test/functional/test_framework/test_framework.py:468 in f68e6b4b3f outdated
     444 | @@ -444,6 +445,9 @@ def set_test_params(self):
     445 |          self.num_nodes = 2
     446 |          self.setup_clean_chain = True
     447 |  
     448 | +    def run_test(self):
    


    WillAyd commented at 6:04 AM on April 2, 2018:

    To more strictly enforce this protocol I had to add this here, even though it just calls the superclass implementation anyway. I figured this is cleaner than making an exception in the metaclass


    jnewbery commented at 5:17 PM on April 2, 2018:

    That's fine. ComparisonTestFramework should hopefully go away very soon (#11818)


    MarcoFalke commented at 12:49 AM on April 5, 2018:

    Needs rebase

  4. fanquake added the label Tests on Apr 2, 2018
  5. fanquake requested review from jnewbery on Apr 2, 2018
  6. WillAyd commented at 3:22 PM on April 2, 2018: contributor

    Hmm have there been intermittent travis failures? I looked into both here but can't see how they would be directly related to the change. Here's a quick summary of them

    26871.1

    $ if [ "$CHECK_DOC" = 1 -a "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then contrib/devtools/lint-all.sh; fi
    src/walletinitinterface.h seems to be missing the expected include guard:
      #ifndef BITCOIN_WALLETINITINTERFACE_H
      #define BITCOIN_WALLETINITINTERFACE_H
      ...
      #endif // BITCOIN_WALLETINITINTERFACE_H
    ^---- failure generated from contrib/devtools/lint-include-guards.sh
    

    26871.3

      File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/test_framework/mininode.py", line 213, in send_message
        raise IOError('Not connected, no pushbuf')
    OSError: Not connected, no pushbuf
    
  7. jnewbery commented at 3:25 PM on April 2, 2018: member

    Hmm have there been intermittent travis failures?

    This failure is caused by a new linter. Rebasing on master will fix this for you.

  8. jnewbery commented at 4:20 PM on April 2, 2018: member

    Concept ACK. I think the metaclass is useful to catch non-conforming tests. However, I think adding unit tests to test the test framework is probably overkill.

    I think I'd prefer this PR if the BitcoinTestMetaClass were just added directly to test_framework.py.

  9. WillAyd commented at 4:23 PM on April 2, 2018: contributor

    Easy enough to revert. Do you want me to include the metaclass directly in test_framework.py instead of putting it in its own module?

  10. MarcoFalke commented at 4:45 PM on April 2, 2018: member

    Jup, that saves one file and one import. I'd agree to that.

  11. jnewbery commented at 5:44 PM on April 2, 2018: member

    Looks good. I'll ACK once commits are squashed.

  12. WillAyd commented at 12:12 AM on April 3, 2018: contributor

    Looks like the failure here was on a make job on Travis but this change shouldn't not impact any compilation - any chance to restart that?

  13. jnewbery commented at 4:10 PM on April 3, 2018: member

    I agree. Travis failure seems unrelated. I've restarted the job.

  14. kallewoof commented at 8:52 AM on April 4, 2018: member

    Travis error is unrelated. utACK, this is very neat! Learned something new.

  15. Tests: Add Metaclass for BitcoinTestFramework
    BitcoinTestFramework instructs developers in its docstring to override
    `set_test_params` and `run_test` in subclasses while being sure NOT to
    override `__init__` and `main` . This change adds a metaclass to ensure
    that developers adhere to that protocol, raising a ``TypeError`` in
    instances where they have not.
    
    closes #12835
    c9cce0a7f6
  16. practicalswift commented at 9:28 PM on April 5, 2018: contributor

    Concept ACK

  17. in test/functional/test_framework/test_framework.py:456 in c9cce0a7f6
     452 | @@ -432,6 +453,7 @@ def _initialize_chain_clean(self):
     453 |          for i in range(self.num_nodes):
     454 |              initialize_datadir(self.options.tmpdir, i)
     455 |  
     456 | +
    


    jnewbery commented at 4:56 PM on April 6, 2018:

    please remove stray newline


    WillAyd commented at 5:02 PM on April 6, 2018:

    That was intentional from our conversation in #12884. This would follow PEP8 so I figured bundle in here. OK to remove still if you want


    jnewbery commented at 5:20 PM on April 6, 2018:

    sure. Fine to leave it in.

  18. jnewbery commented at 4:59 PM on April 6, 2018: member

    Tested ACK c9cce0a7f66e5abe6a94704eb478e0dc52a29f13

    There's a stray newline in your commit. Please remove!

  19. MarcoFalke commented at 5:08 PM on April 6, 2018: member

    utACK c9cce0a7f66e5abe6a94704eb478e0dc52a29f13. (Seems fine to add the new line, since it is already done.)

  20. laanwj commented at 5:44 PM on April 8, 2018: member

    utACK c9cce0a

  21. laanwj merged this on Apr 8, 2018
  22. laanwj closed this on Apr 8, 2018

  23. laanwj referenced this in commit 27278dffe8 on Apr 8, 2018
  24. WillAyd deleted the branch on Apr 8, 2018
  25. deadalnix referenced this in commit 53e142a7ed on Jun 4, 2020
  26. ftrader referenced this in commit 2711cccc71 on Aug 17, 2020
  27. UdjinM6 referenced this in commit 5f3410c9cd on May 21, 2021
  28. UdjinM6 referenced this in commit ddff680749 on May 21, 2021
  29. UdjinM6 referenced this in commit 2b63131199 on May 21, 2021
  30. UdjinM6 referenced this in commit e0eea2db3c on May 22, 2021
  31. kittywhiskers referenced this in commit 9bb1e96c2e on May 25, 2021
  32. MarcoFalke locked this on Sep 8, 2021

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: 2026-04-29 03:15 UTC

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