我不熟悉pytest(和python)。在我所有的测试之前只执行一次的内容集(例如:-启动android仿真器,创建appium驱动程序,实例化所有的页面类,以便在测试中使用它们)。顺便说一句,我有多个班的考试。读了一会儿后,我想@pytest.yield_fixture(scope="session", autouse=True)就能搞定。。但这不是我看到的。。请参阅下面的示例。。在import pytest
class TestBase():
@pytest.yield_fixture(scope="session", autouse=True)
def fixture_session(self):
# start emulator, create driver and instantiate all page
# classes with driver create above
print "\n in fixture_session! @session "
yield
# tear down
print "in fixture_session after yield @session"
@pytest.yield_fixture(scope="module", autouse=True)
def fixture_module(request):
print 'in fixture_module @module'
# tear down
yield
print "in fixture_module after yield @module"
class TestOne(TestBase):
def test_a(self):
# write test with page objects created in TestBase
print "in test_a of TestOne"
def test_b(self):
print "in test_b of TestOne"
class TestTwo(TestBase):
def test_a(self):
print "in test_a of TestTwo"
def test_b(self):
print "in test_b of TestTwo"
运行这个可以
^{pr2}$
我错过了什么??为什么每个测试类执行@pytest.yield_fixture(scope="session", autouse=True),以及为什么在完成测试运行之后会发生崩溃?总而言之,在Pytest中设置测试框架的方法正确吗?在