Skip to content

Commit f89ce1f

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25811: doc: test: suggest multi-line imports in functional test style guide
4edc689 doc: test: suggest multi-line imports in functional test style guide (Sebastian Falbesoner) Pull request description: As long as I remember contributing to functional tests (~2-3 years), it was always kind of an unwritten rule that multi-line imports are preferred over single-line imports in order to reduce the possibility of potential merge conflicts -- at least if more than one symbol from a module is imported. This PR adds this rule to the style guide and adapts the example test accordingly. (Inspired by bitcoin/bitcoin#25792 (comment)). ACKs for top commit: kouloumos: ACK 4edc689 1440000bytes: ACK bitcoin/bitcoin@4edc689 w0xlt: ACK bitcoin/bitcoin@4edc689 fanquake: ACK 4edc689 Tree-SHA512: c7b6ff62f601f4e57cc8334d291662987d6737ebca8d81c063280409f4412302172f1404ec16afc9a13007bcdba55bdab66b9b80363287e287888929cb386584
2 parents deb7ad3 + 4edc689 commit f89ce1f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

test/functional/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ don't have test cases for.
2828
could lead to bugs and issues in the test code.
2929
- Use [type hints](https://docs.python.org/3/library/typing.html) in your code to improve code readability
3030
and to detect possible bugs earlier.
31-
- Avoid wildcard imports
31+
- Avoid wildcard imports.
32+
- If more than one name from a module is needed, use lexicographically sorted multi-line imports
33+
in order to reduce the possibility of potential merge conflicts.
3234
- Use a module-level docstring to describe what the test is testing, and how it
3335
is testing it.
3436
- When subclassing the BitcoinTestFramework, place overrides for the

test/functional/example_test.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
from collections import defaultdict
1515

1616
# Avoid wildcard * imports
17-
from test_framework.blocktools import (create_block, create_coinbase)
18-
from test_framework.messages import CInv, MSG_BLOCK
17+
# Use lexicographically sorted multi-line imports
18+
from test_framework.blocktools import (
19+
create_block,
20+
create_coinbase,
21+
)
22+
from test_framework.messages import (
23+
CInv,
24+
MSG_BLOCK,
25+
)
1926
from test_framework.p2p import (
2027
P2PInterface,
2128
msg_block,

0 commit comments

Comments
 (0)