The design of the current ftputil test suite is from the beginnings of ftputil in the early 2000s.
mock
The used approach for mocking ftplib.FTP
can, if not being careful,
create dependencies between tests, so the mocking approach should be
changed anyway. Since nowadays the mock
package is pretty good I think I
should experiment with using it instead of using the current approach.
I've used the mock
package in another project with good results. That
said, it's possible to write mocking setups that are difficult to
understand. In some cases it may be easier to use conventional mocking.
py.test
py.test is a very flexible testing library that also makes tests more compact. I've known the library for a long time, but haven't used it yet because I assumed the won compactness wouldn't justify the rework. Now, since the tests should be revised anyway, I'd like to try using py.test.
Meanwhile I got some more experience with pytest and I like it. :-)
Pytest has some mocking support but I tend to use the mocking with
unittest.mock
or own mock code if it makes sense.
A while ago, the unit tests have been moved to
pytest
in the sense that I use plainassert
s andpytest.raises
. There might still be some things that could be simplified by using more pytest features.
Because of the move to Python 3 only, I'll use
unittest.mock
instead of the third-partymock
package.
The change of the tests is in progress.
Currently I'm experimenting with a "scripted session" approach (see 4f9039bcbf76540cf0bbbc716f23385c18443e79). So far it seems to work fine. There are downsides though:
Tests must consider how an operation is done internally in ftputil. This is typical for mock-based tests in general.
The approach is quite different from the previous one, so all tests that used
mock_ftplib.py
must be adapted to the new approach.It will get interesting in the upload and download tests as these will need several differently scripted sessions. Let's see how well this works.
Formally accept ticket. I'm already working on this. :-)
Done as of 04c077508cc55d52e1fc3f6c83d901c9016f1610.