- I have a session scoped fixture in conftest.py creating a telnet connection to some host
- The tests use this fixture to send commands to the host
- Some of the tests need to reset the connection (close and reconnect)
All the subsequent tests after the one that performed the connection reset will get the original (dead) telnet handle. Is there a way to deal with this situation beside creating a global connection handle (in conftest for ex)?
conftest.py
@pytest.fixture(scope='session')
def cli(device_params):
with telnetlib.Telnet(**device_params) as device_handle:
yield device_handle
test_x.py
def test_foo(cli):
...
cli.reset()
...
def test_bar(cli):
...
cli.send_command('cmd')
...
buf = self.sock.recv(50) ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host