Skip to content

Commit 99778d9

Browse files
committed
bpd tests: Randomize port number
This is a hacky but effective way to work around a problem when running the tests in parallel where two different test executions want to use the same port.
1 parent a0f326e commit 99778d9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/test_player.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import yaml
3030
import tempfile
3131
from contextlib import contextmanager
32+
import random
3233

3334
from beets.util import confit, py3_path
3435
from beetsplug import bpd
@@ -261,12 +262,17 @@ def tearDown(self):
261262
self.unload_plugins()
262263

263264
@contextmanager
264-
def run_bpd(self, host='localhost', port=9876, password=None,
265+
def run_bpd(self, host='localhost', port=None, password=None,
265266
do_hello=True, second_client=False):
266267
""" Runs BPD in another process, configured with the same library
267268
database as we created in the setUp method. Exposes a client that is
268269
connected to the server, and kills the server at the end.
269270
"""
271+
# Choose a port (randomly) to avoid conflicts between parallel
272+
# tests.
273+
if not port:
274+
port = 9876 + random.randint(0, 10000)
275+
270276
# Create a config file:
271277
config = {
272278
'pluginpath': [py3_path(self.temp_dir)],

0 commit comments

Comments
 (0)