~sschwarzer/ftputil#98: 
Migrate current unit tests to use the `mock` and `py.test` packages

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.

Status
RESOLVED FIXED
Submitter
schwa (unverified)
Assigned to
No-one
Submitted
7 years ago
Updated
7 years ago
Labels
library

schwa (unverified) 5 years ago · edit

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.

schwa (unverified) 4 years ago · edit

A while ago, the unit tests have been moved to pytest in the sense that I use plain asserts and pytest.raises. There might still be some things that could be simplified by using more pytest features.

schwa (unverified) 4 years ago · edit

Because of the move to Python 3 only, I'll use unittest.mock instead of the third-party mock package.

schwa (unverified) 3 years ago · edit

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.

schwa (unverified) 3 years ago · edit

Formally accept ticket. I'm already working on this. :-)

schwa (unverified) 2 years ago · edit

Register here or Log in to comment, or comment via email.