私はpy.testをテストに使用します。py.testのtmpdir setup_class
setup_class()私は私のクラスのコンストラクタのためTMPDIRを使用する必要がで:
class TestMyClass:
def setup_class(self):
self.t = MyClass(path=tmpdir)
def test_test(self):
assert True
と私はエラーがあります:
NameError: name 'tmpdir' is not defined
私はを使用することはできませんが。
def test_needsfiles(tmpdir):
print(tmpdir)
assert 0
それが仕事だが、私は私のクラスのコンストラクタでTMPDIRが必要になります。私はこのコードを使用する場合
。
これを行う方法?
ありがとうございます!
UPD
私はこれを行うにしてみてください。
@pytest.yield_fixture()
def constructor(tmpdir):
_t = MyClass(path=str(tmpdir))
yield _t
class TestMyClass:
def test_test(self, constructor):
pass
をしかし、私は固定具にスコープを使用することはできません。あなたが処理するためにtempfile
モジュールを使用することができます
ScopeMismatch: You tried to access the 'function' scoped fixture 'tmpdir' with a 'module' scoped request object, involved factories
thxですが、質問は** py.test **です – tim