Commit 1fd7b893 authored by Jason Madden's avatar Jason Madden

Attempt better warnings handling.

Also some test tweaks for OSX on Ci.
parent 10d05517
...@@ -55,6 +55,7 @@ else: ...@@ -55,6 +55,7 @@ else:
from .sysinfo import VERBOSE from .sysinfo import VERBOSE
from .sysinfo import WIN from .sysinfo import WIN
from .sysinfo import LINUX from .sysinfo import LINUX
from .sysinfo import OSX
from .sysinfo import LIBUV from .sysinfo import LIBUV
from .sysinfo import CFFI_BACKEND from .sysinfo import CFFI_BACKEND
from .sysinfo import DEBUG from .sysinfo import DEBUG
...@@ -110,6 +111,7 @@ from .skipping import skipWithoutResource ...@@ -110,6 +111,7 @@ from .skipping import skipWithoutResource
from .skipping import skipWithoutExternalNetwork from .skipping import skipWithoutExternalNetwork
from .skipping import skipOnPy2 from .skipping import skipOnPy2
from .skipping import skipOnManylinux from .skipping import skipOnManylinux
from .skipping import skipOnMacOnCI
from .exception import ExpectedException from .exception import ExpectedException
...@@ -177,15 +179,4 @@ mock = mock ...@@ -177,15 +179,4 @@ mock = mock
# zope.interface # zope.interface
try: from zope.interface import verify
from zope.interface import verify
except ImportError:
class verify(object):
@staticmethod
def verifyObject(*_):
import warnings
warnings.warn("zope.interface is not installed; not verifying")
return
verify = verify
...@@ -1273,6 +1273,14 @@ if OSX: ...@@ -1273,6 +1273,14 @@ if OSX:
'test_socket.RecvmsgIntoTCPTest.testRecvmsgIntoGenerator', 'test_socket.RecvmsgIntoTCPTest.testRecvmsgIntoGenerator',
] ]
if RUNNING_ON_CI:
disabled_tests += [
# These sometime timeout. Cannot reproduce locally.
'test_ftp.TestTLS_FTPClassMixin.test_mlsd',
'test_ftp.TestTLS_FTPClassMixin.test_retrlines_too_long',
]
if RESOLVER_ARES and PY38 and not RUNNING_ON_CI: if RESOLVER_ARES and PY38 and not RUNNING_ON_CI:
disabled_tests += [ disabled_tests += [
# When updating to 1.16.0 this was seen locally, but not on CI. # When updating to 1.16.0 this was seen locally, but not on CI.
......
...@@ -623,14 +623,15 @@ def print_list(lst): ...@@ -623,14 +623,15 @@ def print_list(lst):
util.log(' - %s', name) util.log(' - %s', name)
def _setup_environ(debug=False): def _setup_environ(debug=False):
if ('PYTHONWARNINGS' not in os.environ def not_set(key):
return not bool(os.environ.get(key))
if (not_set('PYTHONWARNINGS')
and (not sys.warnoptions and (not sys.warnoptions
# Python 3.7 goes from [] to ['default'] for nothing # Python 3.7 goes from [] to ['default'] for nothing
or sys.warnoptions == ['default'])): or sys.warnoptions == ['default'])):
# action:message:category:module:line # action:message:category:module:line
os.environ['PYTHONWARNINGS'] = ','.join([ os.environ['PYTHONWARNINGS'] = ','.join([
# Enable default warnings such as ResourceWarning.
'default',
# On Python 3[.6], the system site.py module has # On Python 3[.6], the system site.py module has
# "open(fullname, 'rU')" which produces the warning that # "open(fullname, 'rU')" which produces the warning that
# 'U' is deprecated, so ignore warnings from site.py # 'U' is deprecated, so ignore warnings from site.py
...@@ -653,24 +654,26 @@ def _setup_environ(debug=False): ...@@ -653,24 +654,26 @@ def _setup_environ(debug=False):
# without the r'' syntax, leading to DeprecationWarning: invalid # without the r'' syntax, leading to DeprecationWarning: invalid
# escape sequence. This is fixed in 2.0 (Python 3 only). # escape sequence. This is fixed in 2.0 (Python 3 only).
'ignore:::dns.zone:', 'ignore:::dns.zone:',
# Enable default warnings such as ResourceWarning.
'default',
]) ])
if 'PYTHONFAULTHANDLER' not in os.environ: if not_set('PYTHONFAULTHANDLER'):
os.environ['PYTHONFAULTHANDLER'] = 'true' os.environ['PYTHONFAULTHANDLER'] = 'true'
if 'GEVENT_DEBUG' not in os.environ and debug: if not_set('GEVENT_DEBUG') and debug:
os.environ['GEVENT_DEBUG'] = 'debug' os.environ['GEVENT_DEBUG'] = 'debug'
if 'PYTHONTRACEMALLOC' not in os.environ and debug: if not_set('PYTHONTRACEMALLOC') and debug:
# This slows the tests down quite a bit. Reserve # This slows the tests down quite a bit. Reserve
# for debugging. # for debugging.
os.environ['PYTHONTRACEMALLOC'] = '10' os.environ['PYTHONTRACEMALLOC'] = '10'
if 'PYTHONDEVMODE' not in os.environ: if not_set('PYTHONDEVMODE'):
# Python 3.7 and above. # Python 3.7 and above.
os.environ['PYTHONDEVMODE'] = '1' os.environ['PYTHONDEVMODE'] = '1'
if 'PYTHONMALLOC' not in os.environ and debug: if not_set('PYTHONMALLOC') and debug:
# Python 3.6 and above. # Python 3.6 and above.
# This slows the tests down some, but # This slows the tests down some, but
# can detect memory corruption. Unfortunately # can detect memory corruption. Unfortunately
...@@ -682,6 +685,24 @@ def _setup_environ(debug=False): ...@@ -682,6 +685,24 @@ def _setup_environ(debug=False):
os.environ['PYTHONMALLOC'] = 'default' os.environ['PYTHONMALLOC'] = 'default'
os.environ['PYTHONDEVMODE'] = '' os.environ['PYTHONDEVMODE'] = ''
interesting_envs = {
k: os.environ[k]
for k in os.environ
if k.startswith(('PYTHON', 'GEVENT'))
}
widest_k = max(len(k) for k in interesting_envs)
for k, v in sorted(interesting_envs.items()):
util.log('%*s\t=\t%s', widest_k, k, v, color="debug")
util.run(
[
sys.executable,
'-c',
'from __future__ import print_function; '
'import sys; print("sys.warnoptions:\t", sys.warnoptions)',
],
# Don't log the beginning and end of the subprocess.
quiet=True, nested=True)
def main(): def main():
# pylint:disable=too-many-locals,too-many-statements # pylint:disable=too-many-locals,too-many-statements
......
...@@ -377,7 +377,7 @@ def run(command, **kwargs): # pylint:disable=too-many-locals ...@@ -377,7 +377,7 @@ def run(command, **kwargs): # pylint:disable=too-many-locals
assert 'stdout' not in kwargs and 'stderr' not in kwargs, kwargs assert 'stdout' not in kwargs and 'stderr' not in kwargs, kwargs
kwargs['stderr'] = subprocess.STDOUT kwargs['stderr'] = subprocess.STDOUT
kwargs['stdout'] = subprocess.PIPE kwargs['stdout'] = subprocess.PIPE
popen = start(command, quiet=nested, **kwargs) popen = start(command, quiet=quiet, **kwargs)
name = popen.name name = popen.name
try: try:
......
...@@ -86,6 +86,10 @@ class Test(greentest.TestCase): ...@@ -86,6 +86,10 @@ class Test(greentest.TestCase):
self.assertEqual(line, '') self.assertEqual(line, '')
conn.close() conn.close()
@greentest.skipOnMacOnCI(
"Sometimes fails to get the right answers; "
"https://travis-ci.org/github/gevent/gevent/jobs/692184822"
)
@greentest.skipOnLibuvOnTravisOnCPython27( @greentest.skipOnLibuvOnTravisOnCPython27(
"segfaults; " "segfaults; "
"See https://github.com/gevent/gevent/pull/1156") "See https://github.com/gevent/gevent/pull/1156")
......
...@@ -134,6 +134,11 @@ class TestCase(greentest.TestCase): ...@@ -134,6 +134,11 @@ class TestCase(greentest.TestCase):
fd.write(('GET %s HTTP/1.0\r\n\r\n' % url).encode('latin-1')) fd.write(('GET %s HTTP/1.0\r\n\r\n' % url).encode('latin-1'))
fd.flush() fd.flush()
LOCAL_CONN_REFUSED_ERRORS = ()
if greentest.OSX:
# A kernel bug in OS X sometimes results in this
LOCAL_CONN_REFUSED_ERRORS = (errno.EPROTOTYPE,)
def assertConnectionRefused(self): def assertConnectionRefused(self):
with self.assertRaises(socket.error) as exc: with self.assertRaises(socket.error) as exc:
with self.makefile() as conn: with self.makefile() as conn:
...@@ -142,7 +147,7 @@ class TestCase(greentest.TestCase): ...@@ -142,7 +147,7 @@ class TestCase(greentest.TestCase):
ex = exc.exception ex = exc.exception
self.assertIn(ex.args[0], self.assertIn(ex.args[0],
(errno.ECONNREFUSED, errno.EADDRNOTAVAIL, (errno.ECONNREFUSED, errno.EADDRNOTAVAIL,
errno.ECONNRESET, errno.ECONNABORTED), errno.ECONNRESET, errno.ECONNABORTED) + self.LOCAL_CONN_REFUSED_ERRORS,
(ex, ex.args)) (ex, ex.args))
def assert500(self): def assert500(self):
......
...@@ -49,11 +49,16 @@ class TestSSL(test__socket.TestTCP): ...@@ -49,11 +49,16 @@ class TestSSL(test__socket.TestTCP):
# to send a very large amount to make it timeout # to send a very large amount to make it timeout
_test_sendall_data = data_sent = b'hello' * 100000000 _test_sendall_data = data_sent = b'hello' * 100000000
test_sendall_array = greentest.skipOnManylinux("Sometimes misses data")( test_sendall_array = greentest.skipOnMacOnCI("Sometimes misses data")(
test__socket.TestTCP.test_sendall_array greentest.skipOnManylinux("Sometimes misses data")(
test__socket.TestTCP.test_sendall_array
)
) )
test_sendall_str = greentest.skipOnManylinux("Sometimes misses data")(
test__socket.TestTCP.test_sendall_str test_sendall_str = greentest.skipOnMacOnCI("Sometimes misses data")(
greentest.skipOnManylinux("Sometimes misses data")(
test__socket.TestTCP.test_sendall_str
)
) )
@greentest.skipOnWindows("Not clear why we're skipping") @greentest.skipOnWindows("Not clear why we're skipping")
......
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