私はtest1.py以下のコードを持っています
@pytest.fixture(scope="session")
def moduleSetup(request):
module_setup = Module_Setup()
request.addfinalizer(module_setup.teardown())
return module_setup
def test_1(moduleSetup):
print moduleSetup
print '...'
#assert 0
# def test_2(moduleSetup):
# print moduleSetup
# print '...'
# #assert 0
そして、conftest.py私は持っています
class Module_Setup:
def __init__(self):
self.driver = webdriver.Firefox()
def teardown(self):
self.driver.close()
実行すると、ブラウザが起動して閉じます。
しかし、私もエラーが発生しますself = <CallInfo when='teardown' exception: 'NoneType' object is not callable>, func = <function <lambda> at 0x104580488>, when = 'teardown'
また、両方のテストを実行test_1しtest_2、同じドライバー オブジェクトを使用する場合は、スコープmoduleまたはsession?を使用する必要があります。