Python:如何在我的测试套件中制作临时文件? [英] Python: How do I make temporary files in my test suite?
本文介绍了Python:如何在我的测试套件中制作临时文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(我使用的是 Python 2.6 和 nose
.)
(I'm using Python 2.6 and nose
.)
我正在为我的 Python 应用编写测试.我想要一个测试来打开一个新文件,关闭它,然后删除它.自然,我更喜欢这将发生在临时目录中,因为我不想破坏用户的文件系统.而且,它需要是跨操作系统的.
I'm writing tests for my Python app. I want one test to open a new file, close it, and then delete it. Naturally, I prefer that this will happen inside a temporary directory, because I don't want to trash the user's filesystem. And, it needs to be cross-OS.
我该怎么做?
推荐答案
查看 tempfile 标准库中的模块 -- 应该就是你所需要的.
See the tempfile module in the standard library -- should be all you need.
这篇关于Python:如何在我的测试套件中制作临时文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文