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
Родитель 1c5b4db81f
Коммит 39f82971a9
3 изменённых файлов: 23 добавлений и 3 удалений

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

@ -589,7 +589,8 @@ class MarionetteWdspecExecutor(WdspecExecutor):
def do_wdspec(self, session, path, timeout): def do_wdspec(self, session, path, timeout):
harness_result = ("OK", None) 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) return (harness_result, subtest_results)
def do_delayed_imports(self): def do_delayed_imports(self):

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

@ -7,6 +7,7 @@ import webdriver
import contextlib import contextlib
import httplib import httplib
import urlparse
"""pytest fixtures for use in Python-based WPT tests. """pytest fixtures for use in Python-based WPT tests.
@ -130,6 +131,21 @@ class HTTPRequest(object):
finally: finally:
conn.close() 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") @pytest.fixture(scope="module")
def http(session): def http(session):

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

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