-
Notifications
You must be signed in to change notification settings - Fork 159
How to specify two different ports by unused_tcp_port
fixture
#10
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
Comments
Nope, that's the current limitation. I'm not aware for any smaller scope than function, so I suppose we have two options here:
Any ideas? |
I think creating a port factory fixture is a nice approach, while keeping @asvetlov, a quick workaround you can use meanwhile is to create two intermediate fixtures: @pytest.fixture
def port1(unused_tcp_port):
return unused_tcp_port
@pytest.fixture
def port2(unused_tcp_port):
return unused_tcp_port
def test_foo(port1, port2):
... |
@nicoddemus please describe what do you mean under factory fixture? Isn't your workaroud return the same value for |
Oh it's not a pytest term, I just meant a factory in the general sense. Something like this would work nicely IMO: def test_foo(unused_port_factory):
port1 = unused_port_factory.get_port()
port2 = unused_port_factory.get_port()
Argh, of course it is, my bad. Please disregard this. 😅 |
Is |
The idea would be to create it as a fixture, yeah. Fixtures can be any object you like, so yes, they can have methods :) |
Yes, sorry for not being more clear. 😄 |
I'll get this done over the weekend. Beside get_port (I think I prefer next_port instead, so it's clearer it can be called n times and is not idempotent), a method for generating several ports at once might be useful. Like this:
|
👍
Also 👍 |
Sounds perfect! |
I've just pushed out 0.2.0 to PyPI, which includes the unused_tcp_port_factory fixture. The end result is slightly simpler than what we discussed here (see the README), but it should suffice for this use case. |
I believe you even don't need |
I have functional tests for my system which requires several components running on different ports
As I see
unused_tcp_port
has functional scope, so it's impossible to acquire two different ports (for different purposes, sure) in the same test.Or maybe I missed something?
The text was updated successfully, but these errors were encountered: