i think you can use the return value of self patchobject to avoid having to import mock and create a mock object yourself statvfs mock self patchobject os statvfs autospec true statvfs mock return value f flag os st nosuid