Skip to content

start the server with a random unused port and return it in the fixture value #1

@DetachHead

Description

@DetachHead

i'm using pytest-xdist to run tests in parallel, which means this plugin attempts to start multiple servers on port 8000 at the same time:

@pytest.mark.parametrize("index", list(range(6))) # or however many cores you have
def test_foo(index: int, simplehttpserver: Popen[AnyStr]): ...

when running pytest -n auto, some of these tests fail because the port is already in use.

instead, it should be able to find an unused port and return it in the simplehttpserver fixture so the test can tell what port to use:

@pytest.mark.parametrize("index", list(range(6)))
def test_foo(index: int, simplehttpserver: HttpServer):
    print(server.port)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions