2024-10-02 00:31:44 发布
网友
遵循http://py.readthedocs.org/en/latest/path.html#basic-interactive-example处的示例
import py temppath = py.test.ensuretemp('py.path_documentation')
引发错误 AttributeError:“module”对象没有属性“ensuretemp”
Python版本3.4.3,py版本1.4.26。在
py
我做错什么了吗?在
不,你做的每件事都是正确的。我也不能让它工作。另一方面,pytest有fixture tmpdir,它可以满足您在测试中的需要:为您的测试提供唯一的临时目录。在
tmpdir
下面是一个测试示例:
def test_one(tmpdir): test_file = tmpdir.join('dir', 'file').ensure(file=True) test_file.write('test\ntest\n') assert test_file.read().rsplit() == ['test', 'test']
另一方面,pytest使用py.path路径,它有py.path.local对象,并使用tempfile.mkdtemp创建临时目录对象:
tempfile.mkdtemp
您也可以直接从py.path直接使用mkdtemp
py.path
mkdtemp
In [127]: import py.path In [128]: py.path.local.mkdtemp() Out[128]: local('/tmp/tmpP1835f')
不,你做的每件事都是正确的。我也不能让它工作。另一方面,pytest有fixture
tmpdir
,它可以满足您在测试中的需要:为您的测试提供唯一的临时目录。在下面是一个测试示例:
另一方面,pytest使用py.path路径,它有py.path.local对象,并使用
^{pr2}$tempfile.mkdtemp
创建临时目录对象:您也可以直接从
py.path
直接使用mkdtemp
相关问题 更多 >
编程相关推荐