import logging
import os
import sys
import pytest
pytest_plugins = [
'chrome.test.variations.fixtures.cipd',
'chrome.test.variations.fixtures.driver',
'chrome.test.variations.fixtures.http',
'chrome.test.variations.fixtures.result_sink',
'chrome.test.variations.fixtures.seed_locator',
'chrome.test.variations.fixtures.skia_gold',
'chrome.test.variations.fixtures.features',
'chrome.test.variations.fixtures.test_options'
]
def pytest_addoption(parser: pytest.Parser):
parser.addoption('--isolated-script-test-repeat',
'--isolated-script-test-filter',
'--isolated-script-test-launcher-retry-limit',
'--isolated-script-test-perf-output',
'--git-revision',
'--gerrit-issue',
'--gerrit-patchset',
'--buildbucket-id',
'--logs-dir')
parser.addoption('--isolated-script-test-output',
'--write-full-results-to',
'--json-results-file',
dest='json_results_file',
help='If present, store test results on this path.')
parser.addoption('--root-build-dir',
dest='root_build_dir',
help='The path to build output directory. It can be '
'relative to the source root or the absolute path. The path '
'will be added to python search path.')
parser.addoption('--magic-vm-cache',
dest='magic_vm_cache',
help='Path to the magic CrOS VM cache dir. See the comment '
'"magic_cros_vm_cache" in mixins.star for more info.')
def setup_java_path(src_dir: str):
java_home = os.path.join(src_dir, 'third_party', 'jdk', 'current')
java_bin = os.path.join(java_home, 'bin')
os.environ['JAVA_HOME'] = java_home
os.environ['PATH'] = java_bin + os.pathsep + os.environ['PATH']
def pytest_cmdline_main(config: pytest.Config):
src_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), *([os.pardir] * 3)))
setup_java_path(src_dir)
root_build_dir = config.getoption('root_build_dir')
if root_build_dir:
if not os.path.isabs(root_build_dir):
root_build_dir = os.path.join(src_dir, root_build_dir)
logging.info('setting root dir:', root_build_dir)
assert os.path.exists(root_build_dir)
sys.path.append(os.path.abspath(root_build_dir))
magic_vm_cache = config.getoption('magic_vm_cache')
if magic_vm_cache:
full_vm_cache_path = os.path.join(src_dir, magic_vm_cache)
if os.path.exists(full_vm_cache_path):
with open(os.path.join(full_vm_cache_path, 'swarming.txt'), 'w') as f:
f.write('non-empty file to make swarming persist this cache')