-
Notifications
You must be signed in to change notification settings - Fork 37.7k
test: use unittest for test_framework unit testing #18576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
e23585d
to
7a5a8a7
Compare
Concept ACK! @sipa @MarcoFalke you may also be interested in this, since we all discussed this in #18378. |
ef8a510
to
6cc8964
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
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. |
Concept ACK Thanks for tackling this. Great initiative! :) |
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. |
9a36429
to
91bbb49
Compare
91bbb49
to
be5fff5
Compare
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
be5fff5
to
de8905a
Compare
Ready for Review if anyone wants to take a look :) addressed jnewbery's comments. It looks like travis failed on |
Tested ACK de8905a. 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. |
Thanks so much for the review @jnewbery!
Ah, gotcha! Thanks for the feedback :) will do. |
de8905a test: use unittest and test_runner for test framework unit testing (Gloria Zhao) Pull request description: 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](bitcoin#18378 (review))). ACKs for top commit: jnewbery: Tested ACK de8905a. Great stuff gzhao408 . Thanks for this! Tree-SHA512: 91572d43e203a1864765b93a9472667994115ec38b271f2b2f9fcd0f0112b393fc24ba7d2371d5a34b0a6a4522f6b934fc5164363819aa7ed8d6c6c9a60cc101
…some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
…some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
Migrates the CScriptNum decode tests into a unit test, moving some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
Migrates the CScriptNum decode tests into a unit test, moving some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
Migrates the CScriptNum decode tests into a unit test, moving some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
Migrates the CScriptNum decode tests into a unit test, moving some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576. Also adds a unit test testing the decode method with larger ints, similar to the scriptnum_tests.cpp file.
Migrates the CScriptNum decode tests into a unit test, moving some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576. Also extends the original test with larger ints, similar to the scriptnum_tests.cpp file.
Migrates the CScriptNum decode tests into a unit test, and moved some changes made in bitcoin#14816. Made possible by the integration of test_framework unit testing in bitcoin#18576. Further extends the original test with larger ints, similar to the scriptnum_tests.cpp file. Adds test to blocktools.py testing fn create_coinbase() with CScriptNum decode.
Migrates the CScriptNum decode tests into a unit test, and moved some changes made in bitcoin#14816. Made possible by the integration of test_framework unit testing in bitcoin#18576. Further extends the original test with larger ints, similar to the scriptnum_tests.cpp file. Adds test to blocktools.py testing fn create_coinbase() with CScriptNum decode.
Migrates the CScriptNum decode tests into a unit test, and moved some changes made in bitcoin#14816. Made possible by the integration of test_framework unit testing in bitcoin#18576. Further extends the original test with larger ints, similar to the scriptnum_tests.cpp file. Adds test to blocktools.py testing fn create_coinbase() with CScriptNum decode.
Migrates the CScriptNum decode tests into a unit test, and moved some changes made in bitcoin#14816. Made possible by the integration of test_framework unit testing in bitcoin#18576. Further extends the original test with larger ints, similar to the scriptnum_tests.cpp file. Adds test to blocktools.py testing fn create_coinbase() with CScriptNum decode.
Migrates the CScriptNum decode tests into a unit test, and moved some changes made in bitcoin#14816. Made possible by the integration of test_framework unit testing in bitcoin#18576. Further extends the original test with larger ints, similar to the scriptnum_tests.cpp file. Adds test to blocktools.py testing fn create_coinbase() with CScriptNum decode.
…n script.py 7daffc6 [test] CScriptNum Decode Check as Unit Tests (Gillian Chu) Pull request description: The CScriptNum test (#14816) is a roundtrip test of the test framework. Thus, it would be better suited as a unit test. This is now possible with the introduction of the unit test module for the functional tests. See #18576. This PR: 1. Refactors the CScriptNum tests into 2 unit tests, one in script.py and one in blocktools.py. 2. Extends the script.py CScriptNum test to trial larger numbers. ACKs for top commit: laanwj: ACK 7daffc6 Tree-SHA512: 17a04a4bfff1b1817bfc167824c679455d9e06e6e0164c00a7e44f8aa5041c5f5080adcc1452fd80ba1a6d8409f976c982bc481d686c434edf97a5893a32a436
… test in script.py 7daffc6 [test] CScriptNum Decode Check as Unit Tests (Gillian Chu) Pull request description: The CScriptNum test (bitcoin#14816) is a roundtrip test of the test framework. Thus, it would be better suited as a unit test. This is now possible with the introduction of the unit test module for the functional tests. See bitcoin#18576. This PR: 1. Refactors the CScriptNum tests into 2 unit tests, one in script.py and one in blocktools.py. 2. Extends the script.py CScriptNum test to trial larger numbers. ACKs for top commit: laanwj: ACK 7daffc6 Tree-SHA512: 17a04a4bfff1b1817bfc167824c679455d9e06e6e0164c00a7e44f8aa5041c5f5080adcc1452fd80ba1a6d8409f976c982bc481d686c434edf97a5893a32a436
Migrates the CScriptNum decode tests into a unit test, and moved some changes made in bitcoin#14816. Made possible by the integration of test_framework unit testing in bitcoin#18576. Further extends the original test with larger ints, similar to the scriptnum_tests.cpp file. Adds test to blocktools.py testing fn create_coinbase() with CScriptNum decode.
Summary: > 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 This is a backport of Core [[bitcoin/bitcoin#18576 | PR18576]] Test Plan: ninja check-functional Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D9068
Summary: > Migrates the CScriptNum decode tests into a unit test, and moved some > changes made in [[bitcoin/bitcoin#14816 | core#14816]]. Made possible by the integration of > test_framework unit testing in [[bitcoin/bitcoin#18576 | core#18576]]. Further extends the original > test with larger ints, similar to the scriptnum_tests.cpp file. Adds > test to blocktools.py testing fn create_coinbase() with CScriptNum > decode. Backport note: The functional tests are usually executed individually via a `subprocess`. This means the `get_srcdir()` function in cdefs.py is able to find the proper source directory, because the parent directory of the python process is the project root that contains `src/`. But when we run the new test_framework unit test, the process currently running is `test_runner.py` itself which is located in the build directory. So cdefs.py finds the wrong `src/` directory, the one located in the build directory, which does not contain `consensus.h`. I fixed this by setting the environment variable `SRCDIR` in `test_runner.py` before calling the unittest `unittest.TestLoader().loadTestsFromName` machinery which causes `cdefs.py` to be imported. This is a backport of [[bitcoin/bitcoin#19082 | core#19082]] Test Plan: `ninja check-functional` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D9276
Proposal for unit testing on test_framework functions:
unittest
library. Don't use test_framework to test itself.test_runner.py
. To include more Test Framework tests, add the filename to the listTEST_FRAMEWORK_MODULES
. Don't add new files or change the list of accepted script prefixes.Makes these changes for
bn2vch
(followup to this comment).