TST: rework tests to work with Python 2.4

Instead of using the "with" statement, we introduce 'fake_with' function that
does the same.