Opened 4 years ago

Last modified 3 months ago

#98 assigned task

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 (7)

comment:1 Changed 4 years ago by schwa

Type: defecttask

comment:2 Changed 22 months 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 22 months ago by schwa (previous) (diff)

comment:3 Changed 18 months 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 18 months 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 months ago by schwa

Milestone: 4.0.0

comment:6 Changed 3 months 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 months ago by schwa

Status: newassigned

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

Note: See TracTickets for help on using tickets.