Opened 6 years ago

Closed 21 months ago

#98 closed task (fixed)

Migrate current unit tests to use the `mock` and `py.test` packages

Reported by: schwa Owned by: schwa
Priority: major Milestone: 4.0.0
Component: Library Version:
Keywords: mock py.test testing Cc:


The design of the current ftputil test suite is from the beginnings of ftputil in the early 2000s.


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 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.

Change History (8)

comment:1 Changed 6 years ago by schwa

Type: defecttask

comment:2 Changed 4 years ago by schwa

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.

Last edited 4 years ago by schwa (previous) (diff)

comment:3 Changed 4 years ago by schwa

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.

comment:4 Changed 4 years ago by schwa

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

comment:5 Changed 3 years ago by schwa

Milestone: 4.0.0

comment:6 Changed 3 years ago by schwa

The change of the tests is in progress.

Currently I'm experimenting with a "scripted session" approach (see [72d797a82efe]). 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 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.

comment:7 Changed 3 years ago by schwa

Status: newassigned

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

comment:8 Changed 21 months ago by schwa

Resolution: fixed
Status: assignedclosed

Done as of [442b8ca8a85e].

Note: See TracTickets for help on using tickets.