2016-03-21 3 views
1

xdistと組み合わせてpytestを使用してテストを並行して実行しました。私は私のcontest.py私はいくつかのテストデータdirecories(タイムスタンプ付き)を作成するためのconfigureフックがあり、私のテストの実行に必要なファイル。私がxdistを使うまでは、すべて正常に動作します。そのpytest_configureが再びその結果、各プロセスのために再度最初にして実行されたように見えます:pytestはxdistと並行して実行する前にupfrontを設定します

INTERNALERROR> OSError: [Errno 17] File exists: '/path/to/file' 

そして私は、n + 1つのディレクトリ(離れて数秒)で終わります。 配布する前にテストを事前設定する方法はありますか?

編集: 私の問題の解決策を見つけたかもしれませんhere。私はまだそれをテストする必要があります。

+0

私は、あなた自身のロックメカニックを書く必要がありますね。 –

+0

私はそれをどのようにすることができるかの例を教えてもらえますか? –

答えて

1

はい、それは私の問題を解決しました。 linkのサンプルコードを追加しました。フィクスチャを使用してslaveinput dictにデータを注入します。これはマスタプロセスによって書かれたものだけですpytest_configureです。

def pytest_configure(config):   
    if is_master(config): 
     config.shared_directory = os.makedirs('/tests/runs/') 

def pytest_configure_node(self, node): 
    """xdist hook""" 
    node.slaveinput['shared_dir'] = node.config.shared_directory 

@pytest.fixture 
def shared_directory(request): 
    if is_master(request.config): 
     return request.config.shared_directory 
    else: 
     return request.config.slaveinput['shared_dir'] 

def is_master(config): 
    """True if the code running the given pytest.config object is running in a xdist master 
    node or not running xdist at all. 
    """ 
    return not hasattr(config, 'slaveinput') 
関連する問題