A common task in programs I've been working on lately is modifying a text file in some way. (Hey, I'm on Linux. Everything's a file. And I do large-scale system admin.)
But the file the code modifies may not exist on my desktop box. And I probably don't want to modify it if it IS on my desktop.
I've read about unit testing in Dive Into Python, and it's pretty clear what I want to do when testing an app that converts decimal to Roman Numerals (the example in DintoP). The testing is nicely self-contained. You don't need to verify that the program PRINTS the right thing, you just need to verify that the functions are returning the right output to a given input.
In my case, however, we need to test that the program is modifying its environment correctly. Here's what I've come up with:
1) Create the "original" file in a standard location, perhaps /tmp.
2) Run the function that modifies the file, passing it the path to the file in /tmp.
3) Verify that the file in /tmp was changed correctly; pass/fail unit test accordingly.
This seems kludgy to me. (Gets even kludgier if you want to verify that backup copies of the file are created properly, etc.)  Has anyone come up with a better way?
You have two levels of testing.

Filtering and Modifying content.  These are "low-level" operations that don't really require physical file I/O.  These are the tests, decision-making, alternatives, etc.  The "Logic" of the application.
File system operations.  Create, copy, rename, delete, backup.  Sorry, but those are proper file system operations that -- well -- require a proper file system for testing.

For this kind of testing, we often use a "Mock" object.  You can design a "FileSystemOperations" class that embodies the various file system operations.  You test this to be sure it does basic read, write, copy, rename, etc.  There's no real logic in this.  Just methods that invoke file system operations.
You can then create a MockFileSystem which dummies out the various operations.  You can use this Mock object to test your other classes.
In some cases, all of your file system operations are in the os module.  If that's the case, you can create a MockOS module with mock version of the operations you actually use.
Put your MockOS module on the PYTHONPATH and you can conceal the real OS module.
For production operations you use your well-tested "Logic" classes plus your FileSystemOperations class (or the real OS module.)
Unit Testing File Modifications