pytestserver resetting port
Zujiry opened this issue · 4 comments
Hi!
I have the problem that I have set the pytest server in my pytest.ini on module scope, if I use the ftpserver in a new module the port resets to a random one.
Can I prevent that behavior as I want to use the same port in every function?
I tried to close the server after every use, but that does not solve it.
Cheers
Have you tried overriding the environment in each ini?
For example:
$ cat pytest.ini
[pytest]
env =
FTP_USER=benz
FTP_PASS=erni1
FTP_HOME = /home/ftp_test
FTP_PORT=31175
FTP_FIXTURE_SCOPE=function
# only affects ftpserver_TLS
Got the same behavior, I could fix it by not defining a port at all in the pytest.ini
You can try to use session scope, so the server only starts once per test suite run.
The problem is most likely that the server from the first module is still running when the server for the second module starts.
Since only one process can listen to a port, the new server needs to get a different port.
If the port you want to use isn't hardcoded (e.g. passed as an argument or read from a config) you can just use ftpserver.get_login_data()
and use that port.
Have you tried overriding the environment in each ini?
For example:
$ cat pytest.ini [pytest] env = FTP_USER=benz FTP_PASS=erni1 FTP_HOME = /home/ftp_test FTP_PORT=31175 FTP_FIXTURE_SCOPE=function # only affects ftpserver_TLS
I only have one ini file, so that does not help sadly.
Got the same behavior, I could fix it by not defining a port at all in the pytest.ini
Tried that, but then I get a ConnectionRefusedError: [Errno 61] Connection refused
and the port is wrong if I check the server address.
You can try to use session scope, so the server only starts once per test suite run.
The problem is most likely that the server from the first module is still running when the server for the second module starts.
Since only one process can listen to a port, the new server needs to get a different port.If the port you want to use isn't hardcoded (e.g. passed as an argument or read from a config) you can just use
ftpserver.get_login_data()
and use that port.
I have the port hardcoded in my config but could change the port in the config accordingly as a workaround. That does not solve the issue itself though.
It seems that a new server is started for each module (or test.py file) which should be fixed via the scope. Guess it should be function but the old server running on the specified port does not get closed fast enough?