Migrate all Integration Tests to Pytest and Refactor Test Framework#794
Open
moisesPompilio wants to merge 12 commits intogetfloresta:masterfrom
Open
Migrate all Integration Tests to Pytest and Refactor Test Framework#794moisesPompilio wants to merge 12 commits intogetfloresta:masterfrom
moisesPompilio wants to merge 12 commits intogetfloresta:masterfrom
Conversation
Collaborator
Author
|
This PR is not completely ready because some points in the get_txout test still need to be fixed, and the commit messages need improvement. However, you can already get a preview of how the tests look with pytest and how much faster test execution is now. cc: @joaozinhom |
28fe662 to
4d284fa
Compare
jaoleal
reviewed
Feb 11, 2026
tests/floresta-cli/getblock.py
Outdated
Comment on lines
15
to
20
| @pytest.mark.rpc | ||
| def test_get_block(florestad_node): | ||
| """ | ||
| Test `getblock` with a fresh node and the first block with verbose levels 0 and 1 | ||
| Test `getblock` to get the genesis block. | ||
| """ | ||
| florestad = florestad_node |
Collaborator
There was a problem hiding this comment.
Suggested change
| @pytest.mark.rpc | |
| def test_get_block(florestad_node): | |
| """ | |
| Test `getblock` with a fresh node and the first block with verbose levels 0 and 1 | |
| Test `getblock` to get the genesis block. | |
| """ | |
| florestad = florestad_node | |
| @pytest.mark.rpc | |
| def test_get_block(florestad_node, bitcoind_node): | |
| """ | |
| Test `getblock` to get the genesis block. | |
| """ | |
| florestad = florestad_node | |
| bitcoind_node = bitcoind_node | |
| block_serialize = florestad.rpc.get_block(GENESIS_BLOCK_BLOCK, 0) | |
| bblock_serialize = bitcoind_node.rpc.get_block(GENESIS_BLOCK_BLOCK, 0) | |
| assert block_serialize == bblock_serialize | |
| block_verbose = florestad.rpc.get_block(GENESIS_BLOCK_BLOCK, 1) | |
| bblock_verbose = bitcoind_node.rpc.get_block(GENESIS_BLOCK_BLOCK, 1) | |
| # Compare difficulty separately with tolerance due to float precision differences | |
| floresta_difficulty = block_verbose.pop("difficulty") | |
| bitcoind_difficulty = bblock_verbose.pop("difficulty") | |
| assert floresta_difficulty == pytest.approx(bitcoind_difficulty, rel=1e-4) | |
| assert block_verbose == bblock_verbose |
When running this I had to apply the above suggested changes, there we can easily compare directly against core
Collaborator
There was a problem hiding this comment.
I did not rebased this, i just had a different binary version of florestad loaded.
4d284fa to
78a0515
Compare
78a0515 to
20b54e1
Compare
Introduce pytest as the new testing framework to simplify and enhance the way tests are written and executed. Pytest facilitates the creation of reusable functions and fixtures, making it easier to manage and instantiate nodes dynamically. It also provides built-in assertion functions and a robust test runner. co-authored-by: joaozinhom <joaozinhom@users.noreply.github.com>
Introduce multithread support for pytest in the functional tests, enabling tests to run in parallel with a default of 4 workers. To ensure proper isolation and avoid conflicts between tests running simultaneously, the `/data` directory for nodes is now generated dynamically based on the name of the test being executed. This adjustment leverages the `request.node.name` attribute to create unique data directories for each test. co-authored-by: joaozinhom <joaozinhom@users.noreply.github.com>
…test_runner.py Migrated the Electrum example test to use pytest, simplifying the test structure. Removed the requirement for all tests to be listed in test_runner.py, allowing tests to be run independently with pytest. co-authored-by: joaozinhom <joaozinhom@users.noreply.github.com>
…st_runner Convert the following legacy functional/integration tests to pytest style: - tests/floresta-cli/getmemoryinfo.py - tests/floresta-cli/stop.py - tests/floresta-cli/uptime.py - tests/florestad/restart.py - tests/floresta-cli/getroots.py - tests/floresta-cli/getblockchaininfo.py - tests/floresta-cli/getpeerinfo.py - tests/floresta-cli/getblockheader.py - tests/floresta-cli/getrpcinfo.py Remove their legacy registrations from tests/test_runner.py so pytest discovers them natively.
…tls fixture Convert the TLS functional test to pytest (tests/florestad/tls.py) and add a reusable pytest fixture `add_node_with_tls` in tests/conftest.py to create TLS-enabled nodes. Remove the legacy TLS entry from tests/test_runner.py.
- Merge addnode_v1 and addnode_v2 into a single pytest file: tests/floresta-cli/addnode.py, using TestAddNode to encapsulate cases. - Test methods now instantiate the scenario with parameters; TestAddNode executes the assertions, reducing duplication. - Remove legacy addnode_v1/addnode_v2 entries from tests/test_runner.py. - Add pytest fixture `add_node_with_extra_args`` in tests/conftest.py that exposes FlorestaTestFramework.add_node_extra_args for creating nodes with custom args from tests.
Convert `tests/florestad/connect.py` to the pytest style and remove its legacy entry from `tests/test_runner.py.` This standardizes the test and makes it discoverable by pytest.
…to pytest Add a session-scoped `florestad_utreexod` fixture that creates, starts and connects a Florestad + Utreexod pair for reuse in tests. Migrate reorg_chain, getbestblockhash, getblockcount and getblockhash to pytest and remove their legacy registrations from `tests/test_runner.py`
…and migrate tests Add a function-scoped `florestad_bitcoind` fixture that creates, starts and connects a Florestad + Bitcoind pair for each test. Migrate legacy addnode/getpeerinfo/ping/... tests to pytest and remove their legacy registrations from tests/test_runner.py.
- Convert tests/floresta-cli/gettxout.py to pytest style for discovery. - Add RPC helper loaddescriptor in tests/test_framework/rpc/floresta.py to simplify loading wallet descriptors used by the test. - Add florestad_bitcoind_utreexod fixture that instantiates and connects florestad, bitcoind and utreexod for test usage. - Improve synchronization/wait logic in the test to make node sync checks more robust.
…aTestFramework - Removed tests/test_runner.py and consolidated test execution with pytest. - Refactored FlorestaTestFramework to use logging instead of print(). - Fixed warnings handling and configured warnings to be treated as errors to enforce explicit handling. - Removed helper assert functions from the test framework. - Removed configuration that converted prints into pytest logs.
20b54e1 to
e3d8b3e
Compare
e3d8b3e to
7cebeeb
Compare
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description and Notes
This PR migrates all existing integration tests to use the pytest framework, removing the old custom
test_runnerwhich is no longer necessary. TheFlorestaTestFrameworkhas been significantly refactored to align with pytest conventions; custom assertion methods and main entry points have been removed since pytest handles these natively.Key improvements include:
connect: A new helper function has been introduced to automatically connect all nodes to each other in tests, simplifying test code by eliminating repetitive peer connection setup.FlorestaTestFramework.Close: #783
How to verify the changes you have done?
connecthelper function simplifies node connection setup and reduces boilerplate code.