testing/raptor/test/conftest.py
author Henrik Skupin <mail@hskupin.info>
Tue, 14 May 2019 19:32:11 +0000
changeset 535708 09eea8c87cd551a490ac92ebdc99cbb2041f07ee
parent 523149 15d98a1290fa75aa119120ad3b591dff90956bc4
child 540418 70af85b90c1d4a3f4c75f0fe82ed4a7fd69ce67a
permissions -rw-r--r--
Bug 1528236 - [raptor] Use constructor for initialization of raptor instances. r=perftest-reviewers,rwood The patch tries to reduce the amount of initialization code to call when creating a new Raptor class. Initializing the ADBDevice already in the constructor of the RaptorAndroid class is currently not possible because it would mean that a device is immediately created but the "adb" binary is not available for python test jobs. This has to be fixed later. Differential Revision: https://phabricator.services.mozilla.com/D29331

from __future__ import absolute_import

import json
import os
import sys

import pytest

from argparse import Namespace

# need this so raptor imports work both from /raptor and via mach
here = os.path.abspath(os.path.dirname(__file__))
if os.environ.get('SCRIPTSPATH') is not None:
    # in production it is env SCRIPTS_PATH
    mozharness_dir = os.environ['SCRIPTSPATH']
else:
    # locally it's in source tree
    mozharness_dir = os.path.join(here, '../../mozharness')
sys.path.insert(0, mozharness_dir)

from raptor.raptor import RaptorDesktopFirefox


@pytest.fixture(scope='function')
def options(request):
    opts = {
        'app': 'firefox',
        'binary': 'path/to/dummy/browser',
    }

    if hasattr(request.module, 'OPTIONS'):
        opts.update(request.module.OPTIONS)
    return opts


@pytest.fixture(scope='function')
def raptor(options):
    return RaptorDesktopFirefox(**options)


@pytest.fixture(scope='session')
def get_prefs():
    def _inner(browser):
        import raptor
        prefs_dir = os.path.join(raptor.__file__, 'preferences')
        with open(os.path.join(prefs_dir, '{}.json'.format(browser)), 'r') as fh:
            return json.load(fh)


@pytest.fixture(scope='session')
def filedir():
    return os.path.join(here, 'files')


@pytest.fixture
def get_binary():
    from moztest.selftest import fixtures

    def inner(app):
        if app != 'firefox':
            pytest.xfail(reason="{} support not implemented".format(app))

        binary = fixtures.binary()
        if not binary:
            pytest.skip("could not find a {} binary".format(app))
        return binary

    return inner


@pytest.fixture
def create_args():
    args = Namespace(app='firefox',
                     test='raptor-tp6-1',
                     binary='path/to/binary',
                     gecko_profile=False,
                     debug_mode=False,
                     page_cycles=None,
                     page_timeout=None,
                     host=None,
                     run_local=True)

    def inner(**kwargs):
        for next_arg in kwargs:
            print next_arg
            print kwargs[next_arg]
            setattr(args, next_arg, kwargs[next_arg])
        return args

    return inner