Browse Source

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.
master
SomberNight 3 years ago
parent
commit
2863fb4ab4
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 17
      electrum/tests/__init__.py
  2. 15
      electrum/tests/test_storage_upgrade.py

17
electrum/tests/__init__.py

@ -51,6 +51,7 @@ class ElectrumTestCase(SequentialTestCase):
class TestCaseForTestnet(ElectrumTestCase):
"""Class that runs member tests in testnet mode"""
@classmethod
def setUpClass(cls):
@ -61,3 +62,19 @@ class TestCaseForTestnet(ElectrumTestCase):
def tearDownClass(cls):
super().tearDownClass()
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

15
electrum/tests/test_storage_upgrade.py

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save