【发布时间】:2015-08-28 17:37:23
【问题描述】:
按照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。
In [1]: import py
In [2]: dir(py.test)
Out[2]:
['Class',
'Collector',
'File',
'Function',
'Generator',
'Instance',
'Item',
'Module',
'Session',
'UsageError',
'__all__',
'__builtins__',
'__cached__',
'__doc__',
'__file__',
'__loader__',
'__name__',
'__package__',
'__spec__',
'__version__',
'_fillfuncargs',
'_preloadplugins',
'cmdline',
'collect',
'deprecated_call',
'exit',
'fail',
'fixture',
'freeze_includes',
'importorskip',
'main',
'mark',
'raises',
'set_trace',
'skip',
'xfail',
'yield_fixture']
In [4]: py.test.__file__
Out[4]: '/home/vagrant/.virtualenvs/snap/lib/python3.4/site-packages/pytest.py'
我做错了吗?
【问题讨论】:
-
您可能需要
import py.test才能获取属性ensuretemp。 -
运行
dir(py.test)和py.fest.__file__有什么收获? -
@polarise import py.test, py.test.ensuretemp('py.path_documentation') 引发同样的错误
-
运行
py.test会得到什么? -
@user3012759 当我从项目根目录运行 py.test 时,它会加载我的测试并且我的测试通过。
标签: python python-3.4 pytest