Project

General

Profile

Feature #13492

Support pytest fixtures

Added by Wolfgang Schnerring almost 6 years ago. Updated over 3 years ago.

Status:
Rejected
Priority:
Normal (P3)
Assignee:
-
Category:
API/Selenese
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Keywords:

Description

We should add pytest fixtures in addition to zope.testrunner Layers.

Here's a concrete example (depends on fixtures application, application_session to provide the WSGI callable), I'm not sure how to extract this generically.

@pytest.fixture(scope='session')
def httpserver(application_session, request):
    server = gocept.httpserverlayer.wsgi.Layer()
    server.wsgi_app = application_session
    server.setUp()
    server.url = 'http://%s' % server['http_address']
    request.addfinalizer(server.tearDown)
    return server

@pytest.fixture(scope='session')
def webdriver(httpserver, request):
    layer = gocept.selenium.WebdriverLayer(name='WebdriverLayer')
    layer['http_address'] = httpserver['http_address']
    layer.setUp()
    request.addfinalizer(layer.tearDown)
    return layer

@pytest.fixture
def selenium(webdriver, httpserver, application, request):
    auth = 'admin:admin'
    timeout = int(os.environ.get('GOCEPT_SELENIUM_TIMEOUT', 10))
    selenium = gocept.selenium.wd_selenese.Selenese(
        webdriver['seleniumrc'],
        '%s@%s' % (auth, httpserver['http_address']), timeout)
    request.addfinalizer(lambda: selenium.open('/ping'))
    return selenium

def pytest_configure(config):
    # On DEBUG, selenium logs low-level webdriver communication, which includes
    # a base64 dump of the Firefox profile, which really nobody wants to see.
    logging.getLogger('selenium').setLevel(logging.INFO)

History

#1 Updated by Michael Howitz over 3 years ago

  • Status changed from Confirmed to Rejected

Also available in: Atom PDF