tests: add "as_testnet" fn decorator, to run single tests in testnet
As opposed to using TestCaseForTestnet class, this allows having a single class of many related unit tests, some using testnet and some using mainnet constants.
This commit is contained in:
@@ -51,6 +51,7 @@ class ElectrumTestCase(SequentialTestCase):
|
|||||||
|
|
||||||
|
|
||||||
class TestCaseForTestnet(ElectrumTestCase):
|
class TestCaseForTestnet(ElectrumTestCase):
|
||||||
|
"""Class that runs member tests in testnet mode"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
@@ -61,3 +62,19 @@ class TestCaseForTestnet(ElectrumTestCase):
|
|||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
super().tearDownClass()
|
super().tearDownClass()
|
||||||
constants.set_mainnet()
|
constants.set_mainnet()
|
||||||
|
|
||||||
|
|
||||||
|
def as_testnet(func):
|
||||||
|
"""Function decorator to run a single unit test in testnet mode.
|
||||||
|
|
||||||
|
NOTE: this is inherently sequential; tests running in parallel would break things
|
||||||
|
"""
|
||||||
|
def run_test(*args, **kwargs):
|
||||||
|
old_net = constants.net
|
||||||
|
try:
|
||||||
|
constants.set_testnet()
|
||||||
|
func(*args, **kwargs)
|
||||||
|
finally:
|
||||||
|
constants.net = old_net
|
||||||
|
return run_test
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user