2017-05-11 6 views
0

私はpytest fixturesで作業しています。scope = "module"はpytestで動作していないようです

import pytest 

@pytest.yield_fixture 
@pytest.fixture(scope="module") 
def jlt() : 
    print("setup executed") 
    yield None 
    print("tearing up") 

def test_one(jlt) : 
    id = 123 
    assert id == 123 

def test_two(jlt) : 
    id = 456 
    assert id == 456 

を次のように私はこれを実行しています:

py.test -v --capture=no test_jlt.py 

出力は次のようになります。

scope="module"
platform linux2 -- Python 2.7.12, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- /usr/bin/python 
cachedir: ../../.cache 
rootdir: /home/vandana/unix Home/pythonLearn, inifile: pytest.ini 
collected 2 items 

test_jlt.py::test_one setup executed 
PASSEDtearing up 

test_jlt.py::test_two setup executed 
PASSEDtearing up 

が動作していないようです、次のように私のテストモジュールです。フィクスチャーは、モジュール全体に対して1回だけでなく、各機能ごとに実行されています。私は

答えて

2

@pytest.yield_fixtureをすべきかわからない は@pytest.fixtureを置き換えるので、あなたの代わりに@pytest.yield_fixture(scope="module")を使用する必要があります。

pytest 3.xでは、単に@pytest.fixtureを使用して、フィクスチャ内にyieldを使用することができます。これにより、少し単純化されます。

関連する問題