我的Python項目導入pytest
2.9.0罰款沒有任何問題。在PyTest中創建臨時目錄
我想創建一個新的空目錄,它只能保存測試會話的生命週期。我看到pytest提供臨時目錄支持:
https://pytest.org/latest/tmpdir.html
You can use the tmpdir fixture which will provide a temporary directory unique to the test invocation, created in the base temporary directory.
tmpdir is a py.path.local object which offers os.path methods and more. Here is an example test usage:
爲pytest的源代碼顯示def tmpdir
是一個全球性的/模塊功能:https://pytest.org/latest/_modules/_pytest/tmpdir.html
但是我的測試文件失敗:
import pytest
# ...
def test_foo():
p = pytest.tmpdir()
有錯誤:
AttributeError: 'module' object has no attribute 'tmpdir'
做from pytest import tmpdir
失敗:
ImportError: cannot import name tmpdir
該文檔還列出了一些示例。 'def test_foo(tmpdir):'爲你工作嗎? – vaultah
[文檔](http://pytest.org/latest/tmpdir.html)演示瞭如何使用它,[這](http://stackoverflow.com/a/20545394/1832539)SO帖子也有一個例。那對你有用嗎? – idjaw