Bug 1328726 - Add server fixture to pytestrunner; r=ato,jgraham

MozReview-Commit-ID: B64A6ZR2Sz8

--HG--
extra : rebase_source : 9e4de01da5910030b61ec34669b56d9549e4f536
This commit is contained in:
Maja Frydrychowicz 2017-01-09 18:34:30 -05:00
Родитель 515f58f441
Коммит f965cd20c8
3 изменённых файлов: 23 добавлений и 3 удалений

Просмотреть файл

@ -589,7 +589,8 @@ class MarionetteWdspecExecutor(WdspecExecutor):
def do_wdspec(self, session, path, timeout):
harness_result = ("OK", None)
subtest_results = pytestrunner.run(path, session, timeout=timeout)
subtest_results = pytestrunner.run(
path, session, self.server_url, timeout=timeout)
return (harness_result, subtest_results)
def do_delayed_imports(self):

Просмотреть файл

@ -7,6 +7,7 @@ import webdriver
import contextlib
import httplib
import urlparse
"""pytest fixtures for use in Python-based WPT tests.
@ -130,6 +131,21 @@ class HTTPRequest(object):
finally:
conn.close()
class Server(object):
"""Fixture to allow access to wptrunner's base server url.
:param url_getter: Function to get server url from test environment, given
a protocol.
"""
def __init__(self, url_getter):
self.server_url = url_getter
def where_is(self, uri, protocol="http"):
return urlparse.urljoin(self.server_url(protocol), uri)
@pytest.fixture
def server(self, request):
return self
@pytest.fixture(scope="module")
def http(session):

Просмотреть файл

@ -27,12 +27,14 @@ def do_delayed_imports():
import pytest
def run(path, session, timeout=0):
def run(path, session, url_getter, timeout=0):
"""Run Python test at ``path`` in pytest. The provided ``session``
is exposed as a fixture available in the scope of the test functions.
:param path: Path to the test file.
:param session: WebDriver session to expose.
:param url_getter: Function to get server url from test environment, given
a protocol.
:param timeout: Duration before interrupting potentially hanging
tests. If 0, there is no timeout.
@ -46,7 +48,8 @@ def run(path, session, timeout=0):
recorder = SubtestResultRecorder()
plugins = [recorder,
fixtures,
fixtures.Session(session)]
fixtures.Session(session),
fixtures.Server(url_getter)]
# TODO(ato): Deal with timeouts