Commit cbad5a03 authored by Jason Madden's avatar Jason Madden

The testrunner now has an argument for resources, and sets those up based on...

The testrunner now has an argument for resources, and sets those up based on that or the environment variable.
parent 86883c2b
......@@ -7,6 +7,10 @@ environment:
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd"
# Use a fixed hash seed for reproducability
PYTHONHASHSEED: 8675309
# Disable tests that use external network resources;
# too often we get failures to resolve DNS names or failures
# to connect on AppVeyor.
GEVENTTEST_USE_RESOURCES: "-network"
matrix:
......
......@@ -28,12 +28,12 @@ which are tested with `support.is_resource_enabled`.
"""
from __future__ import absolute_import, division, print_function
import os
# This file may be imported early, so it should take care not to import
# things it doesn't need, which means deferred imports.
from . import support
def _get_ALL_RESOURCES():
def get_ALL_RESOURCES():
"Return a fresh list of resource names."
# RESOURCE_NAMES is the list of all known resources, including those that
# shouldn't be enabled by default or when asking for "all" resources.
# ALL_RESOURCES is the list of resources enabled by default or with "all" resources.
......@@ -67,7 +67,7 @@ def _get_ALL_RESOURCES():
return list(ALL_RESOURCES)
def parse_resources(resource_str):
def parse_resources(resource_str=None):
# str -> Sequence[str]
# Parse it like libregrtest.cmdline documents:
......@@ -96,7 +96,11 @@ def parse_resources(resource_str):
# 'none'. Encountering either of those later in the string resets
# it, for ease of working with appending to environment variables.
resources = _get_ALL_RESOURCES()
if resource_str is None:
import os
resource_str = os.environ.get('GEVENTTEST_USE_RESOURCES')
resources = get_ALL_RESOURCES()
if not resource_str:
return resources
......@@ -110,7 +114,7 @@ def parse_resources(resource_str):
if not requested_resource:
continue
if requested_resource == 'all':
resources = list(_get_ALL_RESOURCES())
resources = get_ALL_RESOURCES()
elif requested_resource == 'none':
resources = []
elif requested_resource.startswith('-'):
......@@ -121,10 +125,18 @@ def parse_resources(resource_str):
return resources
def setup_resources(resources=None):
if resources is None:
resources = parse_resources(os.environ.get('GEVENTTEST_USE_RESOURCES'))
"""
Call either with a list of resources or a resource string.
If ``None`` is given, get the resource string from the environment.
"""
if isinstance(resources, str) or resources is None:
resources = parse_resources(resources)
from . import support
support.use_resources = list(resources)
return resources
......
......@@ -12,6 +12,9 @@ from datetime import timedelta
from multiprocessing.pool import ThreadPool
from multiprocessing import cpu_count
from . import util
from .resources import parse_resources
from .resources import setup_resources
from .resources import get_ALL_RESOURCES
from .sysinfo import RUNNING_ON_CI
from .sysinfo import PYPY
from .sysinfo import PY2
......@@ -492,10 +495,38 @@ def main():
parser.add_argument("--verbose", action="store_false", dest='quiet')
parser.add_argument("--debug", action="store_true", default=False)
parser.add_argument("--package", default="gevent.tests")
parser.add_argument('-u', '--use', metavar='RES1,RES2,...',
action='store', type=parse_resources,
help='specify which special resource intensive tests '
'to run. "all" is the default; "none" may also be used. '
'Disable individual resources with a leading -.'
'For example, "-u-network". GEVENTTEST_USE_RESOURCES is used '
'if no argument is given. To only use one resources, specify '
'"-unone,resource".')
parser.add_argument("--travis-fold", metavar="MSG",
help="Emit Travis CI log fold markers around the output.")
parser.add_argument('tests', nargs='*')
options = parser.parse_args()
# options.use will be either None for not given, or a list
# of the last specified -u argument.
if options.use is None:
# The default, which we'll take from the environment, if set.
options.use = parse_resources()
options.use = list(set(options.use))
# Whether or not it came from the environment, put it in the
# environment now. 'none' must be special cased because an empty
# option string means 'all'. Still, we're explicit about that.
if set(options.use) == set(get_ALL_RESOURCES()):
option_str = 'all'
elif options.use:
option_str = ','.join(options.use)
else:
option_str = 'none'
os.environ['GEVENTTEST_USE_RESOURCES'] = option_str
setup_resources(options.use)
# Set this before any test imports in case of 'from .util import QUIET';
# not that this matters much because we spawn tests in subprocesses,
......
......@@ -198,7 +198,8 @@ IGNORED_GEVENT_ENV_KEYS = {
# These should match the defaults.
IGNORED_GEVENT_ENV_ITEMS = {
('GEVENT_RESOLVER', 'thread'),
('GEVENT_RESOLVER_NAMESERVERS', '8.8.8.8')
('GEVENT_RESOLVER_NAMESERVERS', '8.8.8.8'),
('GEVENTTEST_USE_RESOURCES', 'all'),
}
def getname(command, env=None, setenv=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment