diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2017-10-23 16:05:30 -0700 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2018-09-17 14:44:07 -0700 |
commit | 8868305a76e84e2ee00e35b5131b7b98e45f92a1 (patch) | |
tree | 9caa303d099bef32f7a7e9dbdf6e4688f34e3ecb /tests/conftest.py | |
parent | 903f21d99d9e47dfc519c1521f8dbb8b4ff5724a (diff) |
Start overhauling regular SFTP suite.
Includes attempt to split out the longer-lived server component from the
client component, in fixtures
Also starts tweaking early tests so they're less bad. E.g. test_2_close
had its docstring actively disagreeing with its code (which was super
confusing since both were committed at the same time in 2005...)
Diffstat (limited to 'tests/conftest.py')
-rw-r--r-- | tests/conftest.py | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 7d85fa99..ea10d612 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -39,13 +39,15 @@ def make_sftp_folder(client): pass -# TODO: apply at module or session level -# TODO: roll in SFTP folder setup and teardown? -# NOTE: This is defined here for use by both SFTP (normal & 'big') suites. @pytest.fixture(scope='session') -def sftp(): +def sftp_server(): """ - Set up an in-memory SFTP server, returning its corresponding SFTPClient. + Set up an in-memory SFTP server thread. Yields the client Transport/socket. + + The resulting client Transport (along with all the server components) will + be the same object throughout the test session; the `sftp` fixture then + creates new higher level client objects wrapped around the client + Transport, as necessary. """ # Sockets & transports socks = LoopSocket() @@ -56,14 +58,27 @@ def sftp(): # Auth host_key = RSAKey.from_private_key_file(_support('test_rsa.key')) ts.add_server_key(host_key) - # Server & client setup + # Server setup event = threading.Event() server = StubServer() ts.set_subsystem_handler('sftp', SFTPServer, StubSFTPServer) ts.start_server(event, server) - tc.connect(username='slowdive', password='pygmalion') + # Wait (so client has time to connect? Not sure. Old.) event.wait(1.0) - client = SFTP.from_transport(tc) + # Make & yield connection. + tc.connect(username='slowdive', password='pygmalion') + yield tc + # TODO: any need for shutdown? Why didn't old suite do so? Or was that the + # point of the "join all threads from threading module" crap in test.py? + + +@pytest.fixture +def sftp(sftp_server): + """ + Yield an SFTP client connected to the global in-session SFTP server thread. + """ + # Client setup + client = SFTP.from_transport(sftp_server) # Work in 'remote' folder setup (as it wants to use the client) # TODO: how cleanest to make this available to tests? Doing it this way is # marginally less bad than the previous 'global'-using setup, but not by @@ -72,4 +87,8 @@ def sftp(): # Yield client to caller yield client # Clean up - client.rmdir(client.FOLDER) + # TODO: many tests like to close the client; to match old test suite + # behavior we'd need to recreate the entire client? Possibly better to just + # make the "it runs locally, dumbass" explicit & then just use stdlib to + # clean up? + #client.rmdir(client.FOLDER) |