Skip to content

Commit

Permalink
Produce a better environment string for USE_RESOURCES, and actually p…
Browse files Browse the repository at this point in the history
…ass the right version to the environment variable so we're not just adding on.
  • Loading branch information
jamadden committed Apr 29, 2019
1 parent e59a093 commit 0aed91b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
29 changes: 29 additions & 0 deletions src/gevent/testing/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,39 @@ def parse_resources(resource_str=None):
if requested_resource[1:] in resources:
resources.remove(requested_resource[1:])
else:
# TODO: Produce a warning if it's an unknown resource?
resources.append(requested_resource)

return resources

def unparse_resources(resources):
"""
Given a list of enabled resources, produce the correct environment variable
setting to enable (only) that list.
"""
# By default, we assume all resources are enabled, so explicitly
# listing them here doesn't actually disable anything. To do that, we want to
# list the ones that are disabled. This is usually shorter than starting with
# 'none', and manually adding them back in one by one.
#
# 'none' must be special cased because an empty option string
# means 'all'. Still, we're explicit about that.
#
# TODO: Make this produce the minimal output; sometimes 'none' and
# adding would be shorter.

all_resources = set(get_ALL_RESOURCES())
enabled = set(resources)

if enabled == all_resources:
result = 'all'
elif resources:
explicitly_disabled = all_resources - enabled
result = ''.join(sorted('-' + x for x in explicitly_disabled))
else:
result = 'none'
return result


def setup_resources(resources=None):
"""
Expand Down
13 changes: 3 additions & 10 deletions src/gevent/testing/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from . import util
from .resources import parse_resources
from .resources import setup_resources
from .resources import get_ALL_RESOURCES
from .resources import unparse_resources
from .sysinfo import RUNNING_ON_CI
from .sysinfo import PYPY
from .sysinfo import PY2
Expand Down Expand Up @@ -522,15 +522,8 @@ def main():

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
# environment now.
os.environ['GEVENTTEST_USE_RESOURCES'] = unparse_resources(options.use)
setup_resources(options.use)


Expand Down
1 change: 1 addition & 0 deletions src/gevent/tests/test__socket_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ def iter_all_host_addr_pairs(self):
continue
yield name, addr


@greentest.skipIf(greentest.RUNNING_ON_CI,
"This sometimes randomly fails on Travis with ares and on appveyor, beginning Feb 13, 2018")
# Probably due to round-robin DNS,
Expand Down

0 comments on commit 0aed91b

Please sign in to comment.