I like using OS-assigned ports in test servers where a server binds to port 0, and then communicates the OS-chosen port, say, by printing it out.
The linked code uses a pattern and a callback. The callback reads the log file, finds the newest matching pattern, and uses that to determine the port.
Instead, https://github.com/pytest-dev/pytest-xprocess/blob/master/xprocess/xprocess.py#L424 could remember the matching pattern on a class property.
Then important information about the process could be more easily referenced later.