Fail in TestProcessProto.setUp if bitmessage process dies
This commit is contained in:
parent
6c5bb62123
commit
80831754b3
|
@ -32,13 +32,22 @@ class TestProcessProto(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
"""Setup environment and start pybitmessage"""
|
"""Setup environment and start pybitmessage"""
|
||||||
|
cls.flag = False
|
||||||
cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
|
cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
|
||||||
put_signal_file(cls.home, 'unittest.lock')
|
put_signal_file(cls.home, 'unittest.lock')
|
||||||
subprocess.call(cls._process_cmd) # nosec
|
subprocess.call(cls._process_cmd) # nosec
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
cls.pid = int(cls._get_readline('singleton.lock'))
|
try:
|
||||||
|
cls.pid = int(cls._get_readline('singleton.lock'))
|
||||||
|
except TypeError:
|
||||||
|
cls.flag = True
|
||||||
|
return
|
||||||
cls.process = psutil.Process(cls.pid)
|
cls.process = psutil.Process(cls.pid)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
if self.flag:
|
||||||
|
self.fail("%s is not started ):" % self._process_cmd)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_readline(cls, pfile):
|
def _get_readline(cls, pfile):
|
||||||
pfile = os.path.join(cls.home, pfile)
|
pfile = os.path.join(cls.home, pfile)
|
||||||
|
@ -71,7 +80,7 @@ class TestProcessProto(unittest.TestCase):
|
||||||
if not cls._stop_process():
|
if not cls._stop_process():
|
||||||
print(open(os.path.join(cls.home, 'debug.log'), 'rb').read())
|
print(open(os.path.join(cls.home, 'debug.log'), 'rb').read())
|
||||||
cls.process.kill()
|
cls.process.kill()
|
||||||
except psutil.NoSuchProcess:
|
except (psutil.NoSuchProcess, AttributeError):
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
cls._cleanup_files()
|
cls._cleanup_files()
|
||||||
|
|
Reference in New Issue
Block a user