Skip to content

v2.0.x Chore - DRY via setup/teardown for contexts in test #221

Closed
@reactive-firewall

Description

@reactive-firewall

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)

Metadata

Metadata

Labels

CIContinuous Integration ToolingChoreMiscellaneous chores to maintain the projectDuplicateThis issue or pull request already existsPython LangChanges to Python source codeTestingSomething can be verified

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions