File tree Expand file tree Collapse file tree 2 files changed +32
-7
lines changed
Expand file tree Collapse file tree 2 files changed +32
-7
lines changed Original file line number Diff line number Diff line change 33import subprocess
44from shlex import split
55from time import sleep
6+ from twisted .internet import reactor
67from typing import Any , Tuple
78
89import pytest
@@ -172,3 +173,19 @@ def setup_regtest_bitcoind(pytestconfig):
172173 local_command (stop_cmd )
173174 # note, it is better to clean out ~/.bitcoin/regtest but too
174175 # dangerous to automate it here perhaps
176+
177+
178+ @pytest .fixture (autouse = True )
179+ def reset_reactor_state (request ):
180+ """Reset reactor _startedBefore flag after twisted.trial tests.
181+
182+ twisted.trial stops the reactor after each test, which marks it as
183+ _startedBefore=True, preventing subsequent tests from running the reactor.
184+ This fixture resets the flag to allow other tests to use the reactor.
185+ """
186+
187+ def reset_flag ():
188+ if hasattr (reactor , "_startedBefore" ) and reactor ._startedBefore :
189+ if not reactor .running :
190+ reactor ._startedBefore = False
191+ request .addfinalizer (reset_flag )
Original file line number Diff line number Diff line change 44import time
55from twisted .trial import unittest
66from twisted .internet import reactor , task
7+ from twisted .internet .error import AlreadyCancelled
78from jmdaemon import IRCMessageChannel , MessageChannelCollection
89#needed for test framework
910from jmclient import (load_test_config , get_mchannels , jm_single )
@@ -118,13 +119,20 @@ def setUp(self):
118119 dm2 , mc2 , mcc2 = getmc ("irc_receiver" )
119120 mcc .run ()
120121 mcc2 .run ()
121- def cb (m ):
122- #don't try to reconnect
123- m .give_up = True
124- m .tcp_connector .disconnect ()
125- self .addCleanup (cb , mc )
126- self .addCleanup (cb , mc2 )
127- #test_junk_messages()
122+ self .mcc = mcc
123+ self .mcc2 = mcc2
124+ def cancel_delayed_calls ():
125+ for dc in reactor .getDelayedCalls ():
126+ try :
127+ dc .cancel ()
128+ except AlreadyCancelled :
129+ pass
130+ self .addCleanup (cancel_delayed_calls )
131+ def shutdown_mcs ():
132+ self .mcc .shutdown ()
133+ self .mcc2 .shutdown ()
134+ self .addCleanup (shutdown_mcs )
135+ # test_junk_messages()
128136 print ("Got here" )
129137
130138 def test_waiter (self ):
You can’t perform that action at this time.
0 commit comments