
On Mon, Jul 19, 2010 at 2:23 PM, Alexander Belopolsky <alexander.belopolsky@gmail.com> wrote:
On Mon, Jul 19, 2010 at 12:21 AM, Alexander Belopolsky <alexander.belopolsky@gmail.com> wrote:
On Mon, Jul 19, 2010 at 12:12 AM, Eli Bendersky <eliben@gmail.com> wrote: ..
stdout output can be captured, but what about the .cover files? Can a Python unit test create temporary files in tmp/ (or somewhere else) as part of its testing, or is this forbidden?
That's perfectly fine. Grep in the Lib/test directory for 'tempfile.mkdtemp()' to see examples.
Actually the first hit is Lib/test/script_helper.py which contains several utilities that you may find useful.
Yeah, the script_helper.temp_dir CM is especially handy for mucking about on the filesystem. test_cmd_line_script.py and test_runpy.py are other places to look for inspiration on ways to make heavy use of the filesystem for testing without leaving junk behind when the test is over (script_helper was actually born by refactoring the helpers from those two test suites out to a common module). I really should get back to the issue about a temp_dir equivalent worthy of inclusion in the tempfile module at some point, though (there's an unfortunate corner case relating to interpreter shutdown and generators or explicit invocation of __enter__ that causes problems for the script_helper.temp_dir incarnation. The test suite avoids that corner case naturally, but a tempfile.tempdir CM needs to cope with it) Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia