Closed
Description
Consider moving process management to setUp/tearDown
The process creation, monitoring, and cleanup logic is duplicated across test methods. Consider refactoring this into setUp/tearDown methods for better maintainability.
def setUp(self):
self._fixture_port_num = self._always_generate_random_port_WHEN_called()
self.assertIsNotNone(self._fixture_port_num)
self.assertIsInstance(self._fixture_port_num, int)
self.process = None
def tearDown(self):
if self.process and self.process.is_alive():
self.process.terminate()
self.process.close()
def _start_process(self, daemon=False):
_fixture_HEAR_args = [
"--port", str(self._fixture_port_num),
"--groups", "'224.0.0.1'",
"--group", "'224.0.0.1'"
]
args = ["--daemon", "HEAR"] if daemon else ["RECV"]
args.extend(_fixture_HEAR_args)
self.process = Process(
target=multicast.__main__.main,
name="HEAR" if daemon else "RECV",
args=tuple(args)
)
self.process.start()
self.assertIsNotNone(self.process)