Comment

Peter Bengtsson

I'm not entirely sure I understand but I'm sure there are other ways to do it. I think the trick I managed to point out was twofold. That you have to only do it for the file you expect to mock and that you need to use posix.stat_result()

Parent comment

Martin Brochhaus

Let's assume you only want to find out the creation date... Why not create a new method get_cr_date(self, filename): return os.stat(filename).st_crdate Now you can easily mock that method if you use Mock for example: @patch("yourmodule.yourclass.get_cr_date") def test_should_do_sthg_special_when_x_minutes_passed(self, mock_get_cr_date): mock_get_cr_date.return_value = whatever do your test here...