1# Copyright 2023 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from __future__ import annotations 6 7import pathlib 8import sys 9from typing import Union 10 11import pytest 12 13from crossbench import config 14 15is_google_env = config.is_google_env 16root_dir = config.root_dir 17config_dir = config.config_dir 18 19 20def crossbench_dir() -> pathlib.Path: 21 if is_google_env(): 22 return root_dir() 23 return root_dir() / "crossbench" 24 25 26def run_pytest(path: Union[str, pathlib.Path], *args): 27 extra_args = [*args, *sys.argv[1:]] 28 # Run tests single-threaded by default when running the test file directly. 29 if "-n" not in extra_args: 30 extra_args.extend(["-n", "1"]) 31 if "-r" not in extra_args: 32 extra_args.extend(["-r", "s"]) 33 sys.exit(pytest.main([str(path), *extra_args])) 34