Skip to content

Tests: Add Metaclass for BitcoinTestFramework#12856

Merged
laanwj merged 1 commit intobitcoin:masterfrom
WillAyd:meta-tst
Apr 8, 2018
Merged

Tests: Add Metaclass for BitcoinTestFramework#12856
laanwj merged 1 commit intobitcoin:masterfrom
WillAyd:meta-tst

Conversation

@WillAyd
Copy link
Copy Markdown
Contributor

@WillAyd WillAyd commented Apr 2, 2018

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs rebase

@fanquake fanquake added the Tests label Apr 2, 2018
@fanquake fanquake requested a review from jnewbery April 2, 2018 07:03
@WillAyd
Copy link
Copy Markdown
Contributor Author

WillAyd commented Apr 2, 2018

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

@jnewbery
Copy link
Copy Markdown
Contributor

jnewbery commented Apr 2, 2018

Hmm have there been intermittent travis failures?

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

@jnewbery
Copy link
Copy Markdown
Contributor

jnewbery commented Apr 2, 2018

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.

@WillAyd
Copy link
Copy Markdown
Contributor Author

WillAyd commented Apr 2, 2018

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?

@maflcko
Copy link
Copy Markdown
Member

maflcko commented Apr 2, 2018

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

@jnewbery
Copy link
Copy Markdown
Contributor

jnewbery commented Apr 2, 2018

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

@WillAyd
Copy link
Copy Markdown
Contributor Author

WillAyd commented Apr 3, 2018

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?

@jnewbery
Copy link
Copy Markdown
Contributor

jnewbery commented Apr 3, 2018

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

@kallewoof
Copy link
Copy Markdown
Contributor

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

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
@practicalswift
Copy link
Copy Markdown
Contributor

Concept ACK

Copy link
Copy Markdown
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK c9cce0a

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

for i in range(self.num_nodes):
initialize_datadir(self.options.tmpdir, i)


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove stray newline

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. Fine to leave it in.

@maflcko
Copy link
Copy Markdown
Member

maflcko commented Apr 6, 2018

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

@laanwj
Copy link
Copy Markdown
Member

laanwj commented Apr 8, 2018

utACK c9cce0a

@laanwj laanwj merged commit c9cce0a into bitcoin:master Apr 8, 2018
laanwj added a commit that referenced this pull request Apr 8, 2018
c9cce0a Tests: Add Metaclass for BitcoinTestFramework (Will Ayd)

Pull request description:

  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

Tree-SHA512: 5a47a7ead1f18361138cad4374747c4a8f29d25506f7b2c2a8c1c966a0b65e5ccf7317f9a078df8680fdab5d3fb71fee46a159c9f381878a3683c1e9f874abbe
@WillAyd WillAyd deleted the meta-tst branch April 8, 2018 18:31
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 4, 2020
Summary:
c9cce0a Tests: Add Metaclass for BitcoinTestFramework (Will Ayd)

Pull request description:

  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

Tree-SHA512: 5a47a7ead1f18361138cad4374747c4a8f29d25506f7b2c2a8c1c966a0b65e5ccf7317f9a078df8680fdab5d3fb71fee46a159c9f381878a3683c1e9f874abbe

Backport of Core [[bitcoin/bitcoin#12856 | PR12856]]

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, nakihito

Reviewed By: nakihito

Differential Revision: https://reviews.bitcoinabc.org/D6353
ftrader pushed a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Aug 17, 2020
Summary:
c9cce0a Tests: Add Metaclass for BitcoinTestFramework (Will Ayd)

Pull request description:

  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

Tree-SHA512: 5a47a7ead1f18361138cad4374747c4a8f29d25506f7b2c2a8c1c966a0b65e5ccf7317f9a078df8680fdab5d3fb71fee46a159c9f381878a3683c1e9f874abbe

Backport of Core [[bitcoin/bitcoin#12856 | PR12856]]

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, nakihito

Reviewed By: nakihito

Differential Revision: https://reviews.bitcoinabc.org/D6353
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request May 22, 2021
c9cce0a Tests: Add Metaclass for BitcoinTestFramework (Will Ayd)

Pull request description:

  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 bitcoin#12835

Tree-SHA512: 5a47a7ead1f18361138cad4374747c4a8f29d25506f7b2c2a8c1c966a0b65e5ccf7317f9a078df8680fdab5d3fb71fee46a159c9f381878a3683c1e9f874abbe
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metaclass for BitcoinTestFramework

7 participants