-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_get_first_free_port fails randomly #6042
Comments
This was encountered again in #6056. |
Just had a look at the test. My advice would be a major refactoring:
In detail, this test consists of three steps that are all deficient: # target port is free
port = random.randint(50000, 60000)
assert get_first_free_port(start=port) == port This assumes a random port on the machine is free. This is not true, any port can be occupied by the OS at any time. # target port is locked
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.bind(('', port))
assert get_first_free_port(start=port) == port + 1 This opens the port, which may fail, and checks if # no free ports found
with pytest.raises(FreePortNotFoundError):
get_first_free_port(start=port, limit=0) This checks if no range leads to no port. This should be a separate unit test. Suggestions
|
@qstokkink yes, you are right. Thank you for the suggestions, I will implement them soon. |
On
main
. See this test run, for instanceThe text was updated successfully, but these errors were encountered: