Skip to content

Migrate all Integration Tests to Pytest and Refactor Test Framework#794

Open
moisesPompilio wants to merge 12 commits intogetfloresta:masterfrom
moisesPompilio:convert-all-test-pytest
Open

Migrate all Integration Tests to Pytest and Refactor Test Framework#794
moisesPompilio wants to merge 12 commits intogetfloresta:masterfrom
moisesPompilio:convert-all-test-pytest

Conversation

@moisesPompilio
Copy link
Collaborator

@moisesPompilio moisesPompilio commented Jan 19, 2026

Description and Notes

This PR migrates all existing integration tests to use the pytest framework, removing the old custom test_runner which is no longer necessary. The FlorestaTestFramework has 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:

  • Pytest migration: All tests now follow pytest standards and conventions.
  • Logging infrastructure: The RPC, daemon, and electrum classes now use proper logging instead of print statements, improving debuggability and test output clarity.
  • Helper function 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.
  • Framework simplification: Removed unnecessary assertion implementations and main methods from FlorestaTestFramework.

Close: #783

How to verify the changes you have done?

  • Run the integration tests using the traditional command:
    ./tests/run.sh
  • Confirm that pytest is now being used to execute the tests.
  • Verify that all tests pass successfully under the pytest framework.
  • Check the test output to ensure proper logging is used (not print statements) for RPC, daemon, and electrum classes.
  • Review test code to confirm the connect helper function simplifies node connection setup and reduces boilerplate code.

@moisesPompilio
Copy link
Collaborator Author

moisesPompilio commented Jan 19, 2026

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

@Davidson-Souza Davidson-Souza added code quality Generally improves code readability and maintainability Integration Issues related to our integration tests labels Jan 19, 2026
@moisesPompilio moisesPompilio force-pushed the convert-all-test-pytest branch from 28fe662 to 4d284fa Compare January 19, 2026 23:10
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
Copy link
Collaborator

@jaoleal jaoleal Feb 11, 2026

Choose a reason for hiding this comment

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

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I did not rebased this, i just had a different binary version of florestad loaded.

@moisesPompilio moisesPompilio force-pushed the convert-all-test-pytest branch from 4d284fa to 78a0515 Compare February 12, 2026 22:48
@moisesPompilio moisesPompilio marked this pull request as ready for review February 12, 2026 22:50
@moisesPompilio moisesPompilio force-pushed the convert-all-test-pytest branch from 78a0515 to 20b54e1 Compare February 12, 2026 23:23
moisesPompilio and others added 11 commits February 12, 2026 20:41
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.
@moisesPompilio moisesPompilio force-pushed the convert-all-test-pytest branch from 20b54e1 to e3d8b3e Compare February 12, 2026 23:41
@moisesPompilio moisesPompilio force-pushed the convert-all-test-pytest branch from e3d8b3e to 7cebeeb Compare February 12, 2026 23:47
@moisesPompilio
Copy link
Collaborator Author

7cebeeb This PR supersedes #742, it is now complete, it converts all tests to the pytest format and introduces pytest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Generally improves code readability and maintainability Integration Issues related to our integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants