Best Python code snippet using pandera_python
patched_tests_setup.py
Source:patched_tests_setup.py
1# pylint:disable=missing-docstring,invalid-name,too-many-lines2from __future__ import print_function, absolute_import, division3import collections4import contextlib5import functools6import sys7import os8# At least on 3.6+, importing platform9# imports subprocess, which imports selectors. That10# can expose issues with monkey patching. We don't need it11# though.12# import platform13import re14from .sysinfo import RUNNING_ON_APPVEYOR as APPVEYOR15from .sysinfo import RUNNING_ON_TRAVIS as TRAVIS16from .sysinfo import RESOLVER_NOT_SYSTEM as ARES17from .sysinfo import RUN_COVERAGE18from .sysinfo import PYPY19from .sysinfo import PYPY320from .sysinfo import PY321from .sysinfo import PY222from .sysinfo import PY3423from .sysinfo import PY3524from .sysinfo import PY3625from .sysinfo import PY3726from .sysinfo import WIN27from .sysinfo import OSX28from .sysinfo import LIBUV29from .sysinfo import CFFI_BACKEND30from . import flaky31CPYTHON = not PYPY32# By default, test cases are expected to switch and emit warnings if there was none33# If a test is found in this list, it's expected not to switch.34no_switch_tests = '''test_patched_select.SelectTestCase.test_error_conditions35test_patched_ftplib.*.test_all_errors36test_patched_ftplib.*.test_getwelcome37test_patched_ftplib.*.test_sanitize38test_patched_ftplib.*.test_set_pasv39#test_patched_ftplib.TestIPv6Environment.test_af40test_patched_socket.TestExceptions.testExceptionTree41test_patched_socket.Urllib2FileobjectTest.testClose42test_patched_socket.TestLinuxAbstractNamespace.testLinuxAbstractNamespace43test_patched_socket.TestLinuxAbstractNamespace.testMaxName44test_patched_socket.TestLinuxAbstractNamespace.testNameOverflow45test_patched_socket.FileObjectInterruptedTestCase.*46test_patched_urllib.*47test_patched_asyncore.HelperFunctionTests.*48test_patched_httplib.BasicTest.*49test_patched_httplib.HTTPSTimeoutTest.test_attributes50test_patched_httplib.HeaderTests.*51test_patched_httplib.OfflineTest.*52test_patched_httplib.HTTPSTimeoutTest.test_host_port53test_patched_httplib.SourceAddressTest.testHTTPSConnectionSourceAddress54test_patched_select.SelectTestCase.test_error_conditions55test_patched_smtplib.NonConnectingTests.*56test_patched_urllib2net.OtherNetworkTests.*57test_patched_wsgiref.*58test_patched_subprocess.HelperFunctionTests.*59'''60ignore_switch_tests = '''61test_patched_socket.GeneralModuleTests.*62test_patched_httpservers.BaseHTTPRequestHandlerTestCase.*63test_patched_queue.*64test_patched_signal.SiginterruptTest.*65test_patched_urllib2.*66test_patched_ssl.*67test_patched_signal.BasicSignalTests.*68test_patched_threading_local.*69test_patched_threading.*70'''71def make_re(tests):72 tests = [x.strip().replace(r'\.', r'\\.').replace('*', '.*?')73 for x in tests.split('\n') if x.strip()]74 return re.compile('^%s$' % '|'.join(tests))75no_switch_tests = make_re(no_switch_tests)76ignore_switch_tests = make_re(ignore_switch_tests)77def get_switch_expected(fullname):78 """79 >>> get_switch_expected('test_patched_select.SelectTestCase.test_error_conditions')80 False81 >>> get_switch_expected('test_patched_socket.GeneralModuleTests.testCrucialConstants')82 False83 >>> get_switch_expected('test_patched_socket.SomeOtherTest.testHello')84 True85 >>> get_switch_expected("test_patched_httplib.BasicTest.test_bad_status_repr")86 False87 """88 # certain pylint versions mistype the globals as89 # str, not re.90 # pylint:disable=no-member91 if ignore_switch_tests.match(fullname) is not None:92 return None93 if no_switch_tests.match(fullname) is not None:94 return False95 return True96disabled_tests = [97 # The server side takes awhile to shut down98 'test_httplib.HTTPSTest.test_local_bad_hostname',99 'test_threading.ThreadTests.test_PyThreadState_SetAsyncExc',100 # uses some internal C API of threads not available when threads are emulated with greenlets101 'test_threading.ThreadTests.test_join_nondaemon_on_shutdown',102 # asserts that repr(sleep) is '<built-in function sleep>'103 'test_urllib2net.TimeoutTest.test_ftp_no_timeout',104 'test_urllib2net.TimeoutTest.test_ftp_timeout',105 'test_urllib2net.TimeoutTest.test_http_no_timeout',106 'test_urllib2net.TimeoutTest.test_http_timeout',107 # accesses _sock.gettimeout() which is always in non-blocking mode108 'test_urllib2net.OtherNetworkTests.test_ftp',109 # too slow110 'test_urllib2net.OtherNetworkTests.test_urlwithfrag',111 # fails dues to some changes on python.org112 'test_urllib2net.OtherNetworkTests.test_sites_no_connection_close',113 # flaky114 'test_socket.UDPTimeoutTest.testUDPTimeout',115 # has a bug which makes it fail with error: (107, 'Transport endpoint is not connected')116 # (it creates a TCP socket, not UDP)117 'test_socket.GeneralModuleTests.testRefCountGetNameInfo',118 # fails with "socket.getnameinfo loses a reference" while the reference is only "lost"119 # because it is referenced by the traceback - any Python function would lose a reference like that.120 # the original getnameinfo does not "lose" it because it's in C.121 'test_socket.NetworkConnectionNoServer.test_create_connection_timeout',122 # replaces socket.socket with MockSocket and then calls create_connection.123 # this unfortunately does not work with monkey patching, because gevent.socket.create_connection124 # is bound to gevent.socket.socket and updating socket.socket does not affect it.125 # this issues also manifests itself when not monkey patching DNS: http://code.google.com/p/gevent/issues/detail?id=54126 # create_connection still uses gevent.socket.getaddrinfo while it should be using socket.getaddrinfo127 'test_asyncore.BaseTestAPI.test_handle_expt',128 # sends some OOB data and expect it to be detected as such; gevent.select.select does not support that129 # This one likes to check its own filename, but we rewrite130 # the file to a temp location during patching.131 'test_asyncore.HelperFunctionTests.test_compact_traceback',132 'test_signal.WakeupSignalTests.test_wakeup_fd_early',133 # expects time.sleep() to return prematurely in case of a signal;134 # gevent.sleep() is better than that and does not get interrupted (unless signal handler raises an error)135 'test_signal.WakeupSignalTests.test_wakeup_fd_during',136 # expects select.select() to raise select.error(EINTR'interrupted system call')137 # gevent.select.select() does not get interrupted (unless signal handler raises an error)138 # maybe it should?139 'test_signal.SiginterruptTest.test_without_siginterrupt',140 'test_signal.SiginterruptTest.test_siginterrupt_on',141 # these rely on os.read raising EINTR which never happens with gevent.os.read142 'test_subprocess.ProcessTestCase.test_leak_fast_process_del_killed',143 'test_subprocess.ProcessTestCase.test_zombie_fast_process_del',144 # relies on subprocess._active which we don't use145 # Very slow, tries to open lots and lots of subprocess and files,146 # tends to timeout on CI.147 'test_subprocess.ProcessTestCase.test_no_leaking',148 # This test is also very slow, and has been timing out on Travis149 # since November of 2016 on Python 3, but now also seen on Python 2/Pypy.150 'test_subprocess.ProcessTestCase.test_leaking_fds_on_error',151 'test_ssl.ThreadedTests.test_default_ciphers',152 'test_ssl.ThreadedTests.test_empty_cert',153 'test_ssl.ThreadedTests.test_malformed_cert',154 'test_ssl.ThreadedTests.test_malformed_key',155 'test_ssl.NetworkedTests.test_non_blocking_connect_ex',156 # XXX needs investigating157 'test_ssl.NetworkedTests.test_algorithms',158 # The host this wants to use, sha256.tbs-internet.com, is not resolvable159 # right now (2015-10-10), and we need to get Windows wheels160 # This started timing out randomly on Travis in oct/nov 2018. It appears161 # to be something with random number generation taking too long.162 'test_ssl.BasicSocketTests.test_random_fork',163 # Relies on the repr of objects (Py3)164 'test_ssl.BasicSocketTests.test_dealloc_warn',165 'test_urllib2.HandlerTests.test_cookie_redirect',166 # this uses cookielib which we don't care about167 'test_thread.ThreadRunningTests.test__count',168 'test_thread.TestForkInThread.test_forkinthread',169 # XXX needs investigating170 'test_subprocess.POSIXProcessTestCase.test_preexec_errpipe_does_not_double_close_pipes',171 # Does not exist in the test suite until 2.7.4+. Subclasses Popen, and overrides172 # _execute_child. But our version has a different parameter list than the173 # version that comes with PyPy/CPython, so fails with a TypeError.174]175if 'thread' in os.getenv('GEVENT_FILE', ''):176 disabled_tests += [177 'test_subprocess.ProcessTestCase.test_double_close_on_error'178 # Fails with "OSError: 9 invalid file descriptor"; expect GC/lifetime issues179 ]180if LIBUV:181 # epoll appears to work with these just fine in some cases;182 # kqueue (at least on OS X, the only tested kqueue system)183 # never does (failing with abort())184 # (epoll on Raspbian 8.0/Debian Jessie/Linux 4.1.20 works;185 # on a VirtualBox image of Ubuntu 15.10/Linux 4.2.0 both tests fail;186 # Travis CI Ubuntu 12.04 precise/Linux 3.13 causes one of these tests to hang forever)187 # XXX: Retry this with libuv 1.12+188 disabled_tests += [189 # A 2.7 test. Tries to fork, and libuv cannot fork190 'test_signal.InterProcessSignalTests.test_main',191 # Likewise, a forking problem192 'test_signal.SiginterruptTest.test_siginterrupt_off',193 ]194 if PY2:195 if TRAVIS:196 if CPYTHON:197 disabled_tests += [198 # This appears to crash the process, for some reason,199 # but only on CPython 2.7.14 on Travis. Cannot reproduce in200 # 2.7.14 on macOS or 2.7.12 in local Ubuntu 16.04201 'test_subprocess.POSIXProcessTestCase.test_close_fd_0',202 'test_subprocess.POSIXProcessTestCase.test_close_fds_0_1',203 'test_subprocess.POSIXProcessTestCase.test_close_fds_0_2',204 ]205 if PYPY:206 disabled_tests += [207 # This seems to crash the interpreter. I cannot reproduce208 # on macOS or local Linux VM.209 # See https://travis-ci.org/gevent/gevent/jobs/348661604#L709210 'test_smtplib.TooLongLineTests.testLineTooLong',211 ]212 if ARES:213 disabled_tests += [214 # This can timeout with a socket timeout in ssl.wrap_socket(c)215 # on Travis. I can't reproduce locally.216 'test_ssl.ThreadedTests.test_handshake_timeout',217 ]218 if PY3:219 disabled_tests += [220 # This test wants to pass an arbitrary fileno221 # to a socket and do things with it. libuv doesn't like this,222 # it raises EPERM. It is disabled on windows already.223 # It depends on whether we had a fd already open and multiplexed with224 'test_socket.GeneralModuleTests.test_unknown_socket_family_repr',225 # And yes, there's a typo in some versions.226 'test_socket.GeneralModuleTests.test_uknown_socket_family_repr',227 ]228 if PY37:229 disabled_tests += [230 # This test sometimes fails at line 358. It's apparently231 # extremely sensitive to timing.232 'test_selectors.PollSelectorTestCase.test_timeout',233 ]234 if OSX:235 disabled_tests += [236 # XXX: Starting when we upgraded from libuv 1.18.0237 # to 1.19.2, this sometimes (usually) started having238 # a series of calls ('select.poll(0)', 'select.poll(-1)')239 # take longer than the allowed 0.5 seconds. Debugging showed that240 # it was the second call that took longer, for no apparent reason.241 # There doesn't seem to be a change in the source code to libuv that242 # would affect this.243 # XXX-XXX: This actually disables too many tests :(244 'test_selectors.PollSelectorTestCase.test_timeout',245 ]246 if RUN_COVERAGE:247 disabled_tests += [248 # Starting with #1145 this test (actually249 # TestTLS_FTPClassMixin) becomes sensitive to timings250 # under coverage.251 'test_ftplib.TestFTPClass.test_storlines',252 ]253 if sys.platform.startswith('linux'):254 disabled_tests += [255 # crashes with EPERM, which aborts the epoll loop, even256 # though it was allowed in in the first place.257 'test_asyncore.FileWrapperTest.test_dispatcher',258 ]259 if WIN and PY2:260 # From PyPy2-v5.9.0 and CPython 2.7.14, using its version of tests,261 # which do work on darwin (and possibly linux?)262 # I can't produce them in a local VM running Windows 10263 # and the same pypy version.264 disabled_tests += [265 # These, which use asyncore, fail with266 # 'NoneType is not iterable' on 'conn, addr = self.accept()'267 # That returns None when the underlying socket raises268 # EWOULDBLOCK, which it will do because it's set to non-blocking269 # both by gevent and by libuv (at the level below python's knowledge)270 # I can *usually* reproduce these locally; it seems to be some sort271 # of race condition.272 'test_ftplib.TestFTPClass.test_acct',273 'test_ftplib.TestFTPClass.test_all_errors',274 'test_ftplib.TestFTPClass.test_cwd',275 'test_ftplib.TestFTPClass.test_delete',276 'test_ftplib.TestFTPClass.test_dir',277 'test_ftplib.TestFTPClass.test_exceptions',278 'test_ftplib.TestFTPClass.test_getwelcome',279 'test_ftplib.TestFTPClass.test_line_too_long',280 'test_ftplib.TestFTPClass.test_login',281 'test_ftplib.TestFTPClass.test_makepasv',282 'test_ftplib.TestFTPClass.test_mkd',283 'test_ftplib.TestFTPClass.test_nlst',284 'test_ftplib.TestFTPClass.test_pwd',285 'test_ftplib.TestFTPClass.test_quit',286 'test_ftplib.TestFTPClass.test_makepasv',287 'test_ftplib.TestFTPClass.test_rename',288 'test_ftplib.TestFTPClass.test_retrbinary',289 'test_ftplib.TestFTPClass.test_retrbinary_rest',290 'test_ftplib.TestFTPClass.test_retrlines',291 'test_ftplib.TestFTPClass.test_retrlines_too_long',292 'test_ftplib.TestFTPClass.test_rmd',293 'test_ftplib.TestFTPClass.test_sanitize',294 'test_ftplib.TestFTPClass.test_set_pasv',295 'test_ftplib.TestFTPClass.test_size',296 'test_ftplib.TestFTPClass.test_storbinary',297 'test_ftplib.TestFTPClass.test_storbinary_rest',298 'test_ftplib.TestFTPClass.test_storlines',299 'test_ftplib.TestFTPClass.test_storlines_too_long',300 'test_ftplib.TestFTPClass.test_voidcmd',301 'test_ftplib.TestTLS_FTPClass.test_data_connection',302 'test_ftplib.TestTLS_FTPClass.test_control_connection',303 'test_ftplib.TestTLS_FTPClass.test_context',304 'test_ftplib.TestTLS_FTPClass.test_check_hostname',305 'test_ftplib.TestTLS_FTPClass.test_auth_ssl',306 'test_ftplib.TestTLS_FTPClass.test_auth_issued_twice',307 # This one times out, but it's still a non-blocking socket308 'test_ftplib.TestFTPClass.test_makeport',309 # A timeout, possibly because of the way we handle interrupts?310 'test_socketserver.SocketServerTest.test_InterruptedServerSelectCall',311 'test_socketserver.SocketServerTest.test_InterruptServerSelectCall',312 # times out with something about threading?313 # The apparent hang is just after the print of "waiting for server"314 'test_socketserver.SocketServerTest.test_ThreadingTCPServer',315 'test_socketserver.SocketServerTest.test_ThreadingUDPServer',316 'test_socketserver.SocketServerTest.test_TCPServer',317 'test_socketserver.SocketServerTest.test_UDPServer',318 # This one might be like 'test_urllib2_localnet.TestUrlopen.test_https_with_cafile'?319 # XXX: Look at newer pypy and verify our usage of drop/reuse matches320 # theirs.321 'test_httpservers.BaseHTTPServerTestCase.test_command',322 'test_httpservers.BaseHTTPServerTestCase.test_handler',323 'test_httpservers.BaseHTTPServerTestCase.test_head_keep_alive',324 'test_httpservers.BaseHTTPServerTestCase.test_head_via_send_error',325 'test_httpservers.BaseHTTPServerTestCase.test_header_close',326 'test_httpservers.BaseHTTPServerTestCase.test_internal_key_error',327 'test_httpservers.BaseHTTPServerTestCase.test_request_line_trimming',328 'test_httpservers.BaseHTTPServerTestCase.test_return_custom_status',329 'test_httpservers.BaseHTTPServerTestCase.test_send_blank',330 'test_httpservers.BaseHTTPServerTestCase.test_send_error',331 'test_httpservers.BaseHTTPServerTestCase.test_version_bogus',332 'test_httpservers.BaseHTTPServerTestCase.test_version_digits',333 'test_httpservers.BaseHTTPServerTestCase.test_version_invalid',334 'test_httpservers.BaseHTTPServerTestCase.test_version_none',335 'test_httpservers.SimpleHTTPServerTestCase.test_get',336 'test_httpservers.SimpleHTTPServerTestCase.test_head',337 'test_httpservers.SimpleHTTPServerTestCase.test_invalid_requests',338 'test_httpservers.SimpleHTTPServerTestCase.test_path_without_leading_slash',339 'test_httpservers.CGIHTTPServerTestCase.test_invaliduri',340 'test_httpservers.CGIHTTPServerTestCase.test_issue19435',341 # Unexpected timeouts sometimes342 'test_smtplib.TooLongLineTests.testLineTooLong',343 'test_smtplib.GeneralTests.testTimeoutValue',344 ]345 if PYPY:346 disabled_tests += [347 # appears to timeout?348 'test_threading.ThreadTests.test_finalize_with_trace',349 'test_asyncore.DispatcherWithSendTests_UsePoll.test_send',350 'test_asyncore.DispatcherWithSendTests.test_send',351 # More unexpected timeouts352 'test_ssl.ContextTests.test__https_verify_envvar',353 'test_subprocess.ProcessTestCase.test_check_output',354 'test_telnetlib.ReadTests.test_read_eager_A',355 # But on Windows, our gc fix for that doesn't work anyway356 # so we have to disable it.357 'test_urllib2_localnet.TestUrlopen.test_https_with_cafile',358 # These tests hang. see above.359 'test_threading.ThreadJoinOnShutdown.test_1_join_on_shutdown',360 'test_threading.ThreadingExceptionTests.test_print_exception',361 # Our copy of these in test__subprocess.py also hangs.362 # Anything that uses Popen.communicate or directly uses363 # Popen.stdXXX.read hangs. It's not clear why.364 'test_subprocess.ProcessTestCase.test_communicate',365 'test_subprocess.ProcessTestCase.test_cwd',366 'test_subprocess.ProcessTestCase.test_env',367 'test_subprocess.ProcessTestCase.test_stderr_pipe',368 'test_subprocess.ProcessTestCase.test_stdout_pipe',369 'test_subprocess.ProcessTestCase.test_stdout_stderr_pipe',370 'test_subprocess.ProcessTestCase.test_stderr_redirect_with_no_stdout_redirect',371 'test_subprocess.ProcessTestCase.test_stdout_filedes_of_stdout',372 'test_subprocess.ProcessTestcase.test_stdout_none',373 'test_subprocess.ProcessTestcase.test_universal_newlines',374 'test_subprocess.ProcessTestcase.test_writes_before_communicate',375 'test_subprocess.Win32ProcessTestCase._kill_process',376 'test_subprocess.Win32ProcessTestCase._kill_dead_process',377 'test_subprocess.Win32ProcessTestCase.test_shell_sequence',378 'test_subprocess.Win32ProcessTestCase.test_shell_string',379 'test_subprocess.CommandsWithSpaces.with_spaces',380 ]381 if WIN:382 disabled_tests += [383 # This test winds up hanging a long time.384 # Inserting GCs doesn't fix it.385 'test_ssl.ThreadedTests.test_handshake_timeout',386 # These sometimes raise LoopExit, for no apparent reason,387 # mostly but not exclusively on Python 2.388 'test_socket.BufferIOTest.testRecvFromIntoBytearray',389 'test_socket.BufferIOTest.testRecvFromIntoArray',390 'test_socket.BufferIOTest.testRecvIntoArray',391 'test_socket.BufferIOTest.testRecvFromIntoEmptyBuffer',392 'test_socket.BufferIOTest.testRecvFromIntoMemoryview',393 'test_socket.BufferIOTest.testRecvFromIntoSmallBuffer',394 ]395 if PY3:396 disabled_tests += [397 ]398 if APPVEYOR:399 disabled_tests += [400 ]401 if PYPY:402 if TRAVIS:403 disabled_tests += [404 # This sometimes causes a segfault for no apparent reason.405 # See https://travis-ci.org/gevent/gevent/jobs/327328704406 # Can't reproduce locally.407 'test_subprocess.ProcessTestCase.test_universal_newlines_communicate',408 ]409if RUN_COVERAGE and CFFI_BACKEND:410 disabled_tests += [411 # This test hangs in this combo for some reason412 'test_socket.GeneralModuleTests.test_sendall_interrupted',413 # This can get a timeout exception instead of the Alarm414 'test_socket.TCPTimeoutTest.testInterruptedTimeout',415 # This test sometimes gets the wrong answer (due to changed timing?)416 'test_socketserver.SocketServerTest.test_ForkingUDPServer',417 # Timing and signals are off, so a handler exception doesn't get raised.418 # Seen under libev419 'test_signal.InterProcessSignalTests.test_main',420 ]421if PY2:422 if TRAVIS:423 disabled_tests += [424 # When we moved to group:travis_latest and dist:xenial,425 # this started returning a value (33554432L) != 0; presumably426 # because of updated SSL library? Only on CPython.427 'test_ssl.ContextTests.test_options',428 # When we moved to group:travis_latest and dist:xenial,429 # one of the values used started *working* when it was expected to fail.430 # The list of values and systems is long and complex, so431 # presumably something needs to be updated. Only on PyPy.432 'test_ssl.ThreadedTests.test_alpn_protocols',433 ]434def _make_run_with_original(mod_name, func_name):435 @contextlib.contextmanager436 def with_orig():437 mod = __import__(mod_name)438 now = getattr(mod, func_name)439 from gevent.monkey import get_original440 orig = get_original(mod_name, func_name)441 try:442 setattr(mod, func_name, orig)443 yield444 finally:445 setattr(mod, func_name, now)446 return with_orig447@contextlib.contextmanager448def _gc_at_end():449 try:450 yield451 finally:452 import gc453 gc.collect()454 gc.collect()455@contextlib.contextmanager456def _flaky_socket_timeout():457 import socket458 try:459 yield460 except socket.timeout:461 flaky.reraiseFlakyTestTimeout()462# Map from FQN to a context manager that will be wrapped around463# that test.464wrapped_tests = {465}466class _PatchedTest(object):467 def __init__(self, test_fqn):468 self._patcher = wrapped_tests[test_fqn]469 def __call__(self, orig_test_fn):470 @functools.wraps(orig_test_fn)471 def test(*args, **kwargs):472 with self._patcher():473 return orig_test_fn(*args, **kwargs)474 return test475if sys.version_info[:3] <= (2, 7, 11):476 disabled_tests += [477 # These were added/fixed in 2.7.12+478 'test_ssl.ThreadedTests.test__https_verify_certificates',479 'test_ssl.ThreadedTests.test__https_verify_envvar',480 ]481if OSX:482 disabled_tests += [483 'test_subprocess.POSIXProcessTestCase.test_run_abort',484 # causes Mac OS X to show "Python crashes" dialog box which is annoying485 ]486if WIN:487 disabled_tests += [488 # Issue with Unix vs DOS newlines in the file vs from the server489 'test_ssl.ThreadedTests.test_socketserver',490 ]491 # These are a problem on 3.5; on 3.6+ they wind up getting (accidentally) disabled.492 wrapped_tests.update({493 'test_socket.SendfileUsingSendTest.testWithTimeout': _flaky_socket_timeout,494 'test_socket.SendfileUsingSendTest.testOffset': _flaky_socket_timeout,495 'test_socket.SendfileUsingSendTest.testRegularFile': _flaky_socket_timeout,496 'test_socket.SendfileUsingSendTest.testCount': _flaky_socket_timeout,497 })498if PYPY:499 disabled_tests += [500 # Does not exist in the CPython test suite, tests for a specific bug501 # in PyPy's forking. Only runs on linux and is specific to the PyPy502 # implementation of subprocess (possibly explains the extra parameter to503 # _execut_child)504 'test_subprocess.ProcessTestCase.test_failed_child_execute_fd_leak',505 # On some platforms, this returns "zlib_compression", but the test is looking for506 # "ZLIB"507 'test_ssl.ThreadedTests.test_compression',508 ]509# Generic Python 3510if PY3:511 disabled_tests += [512 # Triggers the crash reporter513 'test_threading.SubinterpThreadingTests.test_daemon_threads_fatal_error',514 # Relies on an implementation detail, Thread._tstate_lock515 'test_threading.ThreadTests.test_tstate_lock',516 # Relies on an implementation detail (reprs); we have our own version517 'test_threading.ThreadTests.test_various_ops',518 'test_threading.ThreadTests.test_various_ops_large_stack',519 'test_threading.ThreadTests.test_various_ops_small_stack',520 # Relies on Event having a _cond and an _reset_internal_locks()521 # XXX: These are commented out in the source code of test_threading because522 # this doesn't work.523 # 'lock_tests.EventTests.test_reset_internal_locks',524 # Python bug 13502. We may or may not suffer from this as its525 # basically a timing race condition.526 # XXX Same as above527 # 'lock_tests.EventTests.test_set_and_clear',528 # These tests want to assert on the type of the class that implements529 # `Popen.stdin`; we use a FileObject, but they expect different subclasses530 # from the `io` module531 'test_subprocess.ProcessTestCase.test_io_buffered_by_default',532 'test_subprocess.ProcessTestCase.test_io_unbuffered_works',533 # 3.3 exposed the `endtime` argument to wait accidentally.534 # It is documented as deprecated and not to be used since 3.4535 # This test in 3.6.3 wants to use it though, and we don't have it.536 'test_subprocess.ProcessTestCase.test_wait_endtime',537 # These all want to inspect the string value of an exception raised538 # by the exec() call in the child. The _posixsubprocess module arranges539 # for better exception handling and printing than we do.540 'test_subprocess.POSIXProcessTestCase.test_exception_bad_args_0',541 'test_subprocess.POSIXProcessTestCase.test_exception_bad_executable',542 'test_subprocess.POSIXProcessTestCase.test_exception_cwd',543 # Relies on a 'fork_exec' attribute that we don't provide544 'test_subprocess.POSIXProcessTestCase.test_exception_errpipe_bad_data',545 'test_subprocess.POSIXProcessTestCase.test_exception_errpipe_normal',546 # Python 3 fixed a bug if the stdio file descriptors were closed;547 # we still have that bug548 'test_subprocess.POSIXProcessTestCase.test_small_errpipe_write_fd',549 # Relies on implementation details (some of these tests were added in 3.4,550 # but PyPy3 is also shipping them.)551 'test_socket.GeneralModuleTests.test_SocketType_is_socketobject',552 'test_socket.GeneralModuleTests.test_dealloc_warn',553 'test_socket.GeneralModuleTests.test_repr',554 'test_socket.GeneralModuleTests.test_str_for_enums',555 'test_socket.GeneralModuleTests.testGetaddrinfo',556 ]557 if TRAVIS:558 disabled_tests += [559 # test_cwd_with_relative_executable tends to fail560 # on Travis...it looks like the test processes are stepping561 # on each other and messing up their temp directories. We tend to get things like562 # saved_dir = os.getcwd()563 # FileNotFoundError: [Errno 2] No such file or directory564 'test_subprocess.ProcessTestCase.test_cwd_with_relative_arg',565 'test_subprocess.ProcessTestCaseNoPoll.test_cwd_with_relative_arg',566 'test_subprocess.ProcessTestCase.test_cwd_with_relative_executable',567 ]568 wrapped_tests.update({569 # XXX: BUG: We simply don't handle this correctly. On CPython,570 # we wind up raising a BlockingIOError and then571 # BrokenPipeError and then some random TypeErrors, all on the572 # server. CPython 3.5 goes directly to socket.send() (via573 # socket.makefile), whereas CPython 3.6 uses socket.sendall().574 # On PyPy, the behaviour is much worse: we hang indefinitely, perhaps exposing a problem575 # with our signal handling.576 # In actuality, though, this test doesn't fully test the EINTR it expects577 # to under gevent (because if its EWOULDBLOCK retry behaviour.)578 # Instead, the failures were all due to `pthread_kill` trying to send a signal579 # to a greenlet instead of a real thread. The solution is to deliver the signal580 # to the real thread by letting it get the correct ID.581 'test_wsgiref.IntegrationTests.test_interrupted_write': _make_run_with_original('threading', 'get_ident')582 })583# PyPy3 3.5.5 v5.8-beta584if PYPY3:585 disabled_tests += [586 # This raises 'RuntimeError: reentrant call' when exiting the587 # process tries to close the stdout stream; no other platform does this.588 # Seen in both 3.3 and 3.5 (5.7 and 5.8)589 'test_signal.SiginterruptTest.test_siginterrupt_off',590 ]591if PYPY and PY3:592 disabled_tests += [593 # This fails to close all the FDs, at least on CI. On OS X, many of the594 # POSIXProcessTestCase fd tests have issues.595 'test_subprocess.POSIXProcessTestCase.test_close_fds_when_max_fd_is_lowered',596 # This has the wrong constants in 5.8 (but worked in 5.7), at least on597 # OS X. It finds "zlib compression" but expects "ZLIB".598 'test_ssl.ThreadedTests.test_compression',599 # The below are new with 5.10.1600 # This gets an EOF in violation of protocol; again, even without gevent601 # (at least on OS X; it's less consistent about that on travis)602 'test_ssl.NetworkedBIOTests.test_handshake',603 ]604 if OSX:605 disabled_tests += [606 # These all fail with "invalid_literal for int() with base 10: b''"607 'test_subprocess.POSIXProcessTestCase.test_close_fds',608 'test_subprocess.POSIXProcessTestCase.test_close_fds_after_preexec',609 'test_subprocess.POSIXProcessTestCase.test_pass_fds',610 'test_subprocess.POSIXProcessTestCase.test_pass_fds_inheritable',611 'test_subprocess.POSIXProcessTestCase.test_pipe_cloexec',612 # The below are new with 5.10.1613 # These fail with 'OSError: received malformed or improperly truncated ancillary data'614 'test_socket.RecvmsgSCMRightsStreamTest.testCmsgTruncLen0',615 'test_socket.RecvmsgSCMRightsStreamTest.testCmsgTruncLen0Plus1',616 'test_socket.RecvmsgSCMRightsStreamTest.testCmsgTruncLen1',617 'test_socket.RecvmsgSCMRightsStreamTest.testCmsgTruncLen2Minus1',618 # Using the provided High Sierra binary, these fail with619 # 'ValueError: invalid protocol version _SSLMethod.PROTOCOL_SSLv3'.620 # gevent code isn't involved and running them unpatched has the same issue.621 'test_ssl.ContextTests.test_constructor',622 'test_ssl.ContextTests.test_protocol',623 'test_ssl.ContextTests.test_session_stats',624 'test_ssl.ThreadedTests.test_echo',625 'test_ssl.ThreadedTests.test_protocol_sslv23',626 'test_ssl.ThreadedTests.test_protocol_sslv3',627 'test_ssl.ThreadedTests.test_protocol_tlsv1',628 'test_ssl.ThreadedTests.test_protocol_tlsv1_1',629 # This gets None instead of http1.1, even without gevent630 'test_ssl.ThreadedTests.test_npn_protocols',631 # This fails to decode a filename even without gevent,632 # at least on High Sierarr.633 'test_httpservers.SimpleHTTPServerTestCase.test_undecodable_filename',634 ]635 disabled_tests += [636 # This seems to be a buffering issue? Something isn't637 # getting flushed. (The output is wrong). Under PyPy3 5.7,638 # I couldn't reproduce locally in Ubuntu 16 in a VM639 # or a laptop with OS X. Under 5.8.0, I can reproduce it, but only640 # when run by the testrunner, not when run manually on the command line,641 # so something is changing in stdout buffering in those situations.642 'test_threading.ThreadJoinOnShutdown.test_2_join_in_forked_process',643 'test_threading.ThreadJoinOnShutdown.test_1_join_in_forked_process',644 ]645 if TRAVIS:646 disabled_tests += [647 # Likewise, but I haven't produced it locally.648 'test_threading.ThreadJoinOnShutdown.test_1_join_on_shutdown',649 ]650if PYPY:651 wrapped_tests.update({652 # XXX: gevent: The error that was raised by that last call653 # left a socket open on the server or client. The server gets654 # to http/server.py(390)handle_one_request and blocks on655 # self.rfile.readline which apparently is where the SSL656 # handshake is done. That results in the exception being657 # raised on the client above, but apparently *not* on the658 # server. Consequently it sits trying to read from that659 # socket. On CPython, when the client socket goes out of scope660 # it is closed and the server raises an exception, closing the661 # socket. On PyPy, we need a GC cycle for that to happen.662 # Without the socket being closed and exception being raised,663 # the server cannot be stopped (it runs each request in the664 # same thread that would notice it had been stopped), and so665 # the cleanup method added by start_https_server to stop the666 # server blocks "forever".667 # This is an important test, so rather than skip it in patched_tests_setup,668 # we do the gc before we return.669 'test_urllib2_localnet.TestUrlopen.test_https_with_cafile': _gc_at_end,670 })671if PY34 and sys.version_info[:3] < (3, 4, 4):672 # Older versions have some issues with the SSL tests. Seen on Appveyor673 disabled_tests += [674 'test_ssl.ContextTests.test_options',675 'test_ssl.ThreadedTests.test_protocol_sslv23',676 'test_ssl.ThreadedTests.test_protocol_sslv3',677 'test_httplib.HTTPSTest.test_networked',678 ]679if PY34:680 disabled_tests += [681 'test_subprocess.ProcessTestCase.test_threadsafe_wait',682 # XXX: It seems that threading.Timer is not being greened properly, possibly683 # due to a similar issue to what gevent.threading documents for normal threads.684 # In any event, this test hangs forever685 'test_subprocess.POSIXProcessTestCase.test_preexec_errpipe_does_not_double_close_pipes',686 # Subclasses Popen, and overrides _execute_child. Expects things to be done687 # in a particular order in an exception case, but we don't follow that688 # exact order689 'test_selectors.PollSelectorTestCase.test_above_fd_setsize',690 # This test attempts to open many many file descriptors and691 # poll on them, expecting them all to be ready at once. But692 # libev limits the number of events it will return at once. Specifically,693 # on linux with epoll, it returns a max of 64 (ev_epoll.c).694 # XXX: Hangs (Linux only)695 'test_socket.NonBlockingTCPTests.testInitNonBlocking',696 # We don't handle the Linux-only SOCK_NONBLOCK option697 'test_socket.NonblockConstantTest.test_SOCK_NONBLOCK',698 # Tries to use multiprocessing which doesn't quite work in699 # monkey_test module (Windows only)700 'test_socket.TestSocketSharing.testShare',701 # Windows-only: Sockets have a 'ioctl' method in Python 3702 # implemented in the C code. This test tries to check703 # for the presence of the method in the class, which we don't704 # have because we don't inherit the C implementation. But705 # it should be found at runtime.706 'test_socket.GeneralModuleTests.test_sock_ioctl',707 # See comments for 2.7; these hang708 'test_httplib.HTTPSTest.test_local_good_hostname',709 'test_httplib.HTTPSTest.test_local_unknown_cert',710 # XXX This fails for an unknown reason711 'test_httplib.HeaderTests.test_parse_all_octets',712 ]713 if OSX:714 disabled_tests += [715 # These raise "OSError: 12 Cannot allocate memory" on both716 # patched and unpatched runs717 'test_socket.RecvmsgSCMRightsStreamTest.testFDPassEmpty',718 ]719 if sys.version_info[:2] == (3, 4):720 disabled_tests += [721 # These are all expecting that a signal (sigalarm) that722 # arrives during a blocking call should raise723 # InterruptedError with errno=EINTR. gevent does not do724 # this, instead its loop keeps going and raises a timeout725 # (which fails the test). HOWEVER: Python 3.5 fixed this726 # problem and started raising a timeout,727 # (https://docs.python.org/3/whatsnew/3.5.html#pep-475-retry-system-calls-failing-with-eintr)728 # and removed these tests (InterruptedError is no longer729 # raised). So basically, gevent was ahead of its time.730 'test_socket.InterruptedRecvTimeoutTest.testInterruptedRecvIntoTimeout',731 'test_socket.InterruptedRecvTimeoutTest.testInterruptedRecvTimeout',732 'test_socket.InterruptedRecvTimeoutTest.testInterruptedRecvfromIntoTimeout',733 'test_socket.InterruptedRecvTimeoutTest.testInterruptedRecvfromTimeout',734 'test_socket.InterruptedRecvTimeoutTest.testInterruptedSendTimeout',735 'test_socket.InterruptedRecvTimeoutTest.testInterruptedSendtoTimeout',736 'test_socket.InterruptedRecvTimeoutTest.testInterruptedRecvmsgTimeout',737 'test_socket.InterruptedRecvTimeoutTest.testInterruptedRecvmsgIntoTimeout',738 'test_socket.InterruptedSendTimeoutTest.testInterruptedSendmsgTimeout',739 ]740 if TRAVIS:741 # This has been seen to produce "Inconsistency detected by742 # ld.so: dl-open.c: 231: dl_open_worker: Assertion743 # `_dl_debug_initialize (0, args->nsid)->r_state ==744 # RT_CONSISTENT' failed!" and fail.745 disabled_tests += [746 'test_threading.ThreadTests.test_is_alive_after_fork',747 ]748 if TRAVIS:749 disabled_tests += [750 'test_subprocess.ProcessTestCase.test_double_close_on_error',751 # This test is racy or OS-dependent. It passes locally (sufficiently fast machine)752 # but fails under Travis753 ]754if PY35:755 disabled_tests += [756 # XXX: Hangs757 'test_ssl.ThreadedTests.test_nonblocking_send',758 'test_ssl.ThreadedTests.test_socketserver',759 # Uses direct sendfile, doesn't properly check for it being enabled760 'test_socket.GeneralModuleTests.test__sendfile_use_sendfile',761 # Relies on the regex of the repr having the locked state (TODO: it'd be nice if762 # we did that).763 # XXX: These are commented out in the source code of test_threading because764 # this doesn't work.765 # 'lock_tests.LockTests.lest_locked_repr',766 # 'lock_tests.LockTests.lest_repr',767 # Added between 3.6.0 and 3.6.3, uses _testcapi and internals768 # of the subprocess module.769 'test_subprocess.POSIXProcessTestCase.test_stopped',770 # This test opens a socket, creates a new socket with the same fileno,771 # closes the original socket (and hence fileno) and then772 # expects that the calling setblocking() on the duplicate socket773 # will raise an error. Our implementation doesn't work that way because774 # setblocking() doesn't actually touch the file descriptor.775 # That's probably OK because this was a GIL state error in CPython776 # see https://github.com/python/cpython/commit/fa22b29960b4e683f4e5d7e308f674df2620473c777 'test_socket.TestExceptions.test_setblocking_invalidfd',778 ]779 if ARES:780 disabled_tests += [781 # These raise different errors or can't resolve782 # the IP address correctly783 'test_socket.GeneralModuleTests.test_host_resolution',784 'test_socket.GeneralModuleTests.test_getnameinfo',785 ]786 if sys.version_info[1] == 5:787 disabled_tests += [788 # This test tends to time out, but only under 3.5, not under789 # 3.6 or 3.7. Seen with both libev and libuv790 'test_socket.SendfileUsingSendTest.testWithTimeoutTriggeredSend',791 ]792if sys.version_info[:3] <= (3, 5, 1):793 # Python issue 26499 was fixed in 3.5.2 and these tests were added.794 disabled_tests += [795 'test_httplib.BasicTest.test_mixed_reads',796 'test_httplib.BasicTest.test_read1_bound_content_length',797 'test_httplib.BasicTest.test_read1_content_length',798 'test_httplib.BasicTest.test_readline_bound_content_length',799 'test_httplib.BasicTest.test_readlines_content_length',800 ]801if PY36:802 disabled_tests += [803 'test_threading.MiscTestCase.test__all__',804 ]805 # We don't actually implement socket._sendfile_use_sendfile,806 # so these tests, which think they're using that and os.sendfile,807 # fail.808 disabled_tests += [809 'test_socket.SendfileUsingSendfileTest.testCount',810 'test_socket.SendfileUsingSendfileTest.testCountSmall',811 'test_socket.SendfileUsingSendfileTest.testCountWithOffset',812 'test_socket.SendfileUsingSendfileTest.testOffset',813 'test_socket.SendfileUsingSendfileTest.testRegularFile',814 'test_socket.SendfileUsingSendfileTest.testWithTimeout',815 'test_socket.SendfileUsingSendfileTest.testEmptyFileSend',816 'test_socket.SendfileUsingSendfileTest.testNonBlocking',817 'test_socket.SendfileUsingSendfileTest.test_errors',818 ]819 # Ditto820 disabled_tests += [821 'test_socket.GeneralModuleTests.test__sendfile_use_sendfile',822 ]823 disabled_tests += [824 # This test requires Linux >= 4.3. When we were running 'dist:825 # trusty' on the 4.4 kernel, it passed (~July 2017). But when826 # trusty became the default dist in September 2017 and updated827 # the kernel to 4.11.6, it begain failing. It fails on `res =828 # op.recv(assoclen + len(plain) + taglen)` (where 'op' is the829 # client socket) with 'OSError: [Errno 22] Invalid argument'830 # for unknown reasons. This is *after* having successfully831 # called `op.sendmsg_afalg`. Post 3.6.0, what we test with,832 # the test was changed to require Linux 4.9 and the data was changed,833 # so this is not our fault. We should eventually update this when we834 # update our 3.6 version.835 # See https://bugs.python.org/issue29324836 'test_socket.LinuxKernelCryptoAPI.test_aead_aes_gcm',837 ]838if PY37:839 disabled_tests += [840 # These want to use the private '_communicate' method, which841 # our Popen doesn't have.842 'test_subprocess.MiscTests.test_call_keyboardinterrupt_no_kill',843 'test_subprocess.MiscTests.test_context_manager_keyboardinterrupt_no_kill',844 'test_subprocess.MiscTests.test_run_keyboardinterrupt_no_kill',845 # This wants to check that the underlying fileno is blocking,846 # but it isn't.847 'test_socket.NonBlockingTCPTests.testSetBlocking',848 # 3.7b2 made it impossible to instantiate SSLSocket objects849 # directly, and this tests for that, but we don't follow that change.850 'test_ssl.BasicSocketTests.test_private_init',851 # 3.7b2 made a change to this test that on the surface looks incorrect,852 # but it passes when they run it and fails when we do. It's not853 # clear why.854 'test_ssl.ThreadedTests.test_check_hostname_idn',855 ]856 if APPVEYOR:857 disabled_tests += [858 ]859# if 'signalfd' in os.environ.get('GEVENT_BACKEND', ''):860# # tests that don't interact well with signalfd861# disabled_tests.extend([862# 'test_signal.SiginterruptTest.test_siginterrupt_off',863# 'test_socketserver.SocketServerTest.test_ForkingTCPServer',864# 'test_socketserver.SocketServerTest.test_ForkingUDPServer',865# 'test_socketserver.SocketServerTest.test_ForkingUnixStreamServer'])866# LibreSSL reports OPENSSL_VERSION_INFO (2, 0, 0, 0, 0) regardless of its version,867# so this is known to fail on some distros. We don't want to detect this because we868# don't want to trigger the side-effects of importing ssl prematurely if we will869# be monkey-patching, so we skip this test everywhere. It doesn't do much for us870# anyway.871disabled_tests += [872 'test_ssl.BasicSocketTests.test_openssl_version'873]874# Now build up the data structure we'll use to actually find disabled tests875# to avoid a linear scan for every file (it seems the list could get quite large)876# (First, freeze the source list to make sure it isn't modified anywhere)877def _build_test_structure(sequence_of_tests):878 _disabled_tests = frozenset(sequence_of_tests)879 disabled_tests_by_file = collections.defaultdict(set)880 for file_case_meth in _disabled_tests:881 file_name, _case, _meth = file_case_meth.split('.')882 by_file = disabled_tests_by_file[file_name]883 by_file.add(file_case_meth)884 return disabled_tests_by_file885_disabled_tests_by_file = _build_test_structure(disabled_tests)886_wrapped_tests_by_file = _build_test_structure(wrapped_tests)887def disable_tests_in_source(source, filename):888 # Source and filename are both native strings.889 if filename.startswith('./'):890 # turn "./test_socket.py" (used for auto-complete) into "test_socket.py"891 filename = filename[2:]892 if filename.endswith('.py'):893 filename = filename[:-3]894 # XXX ignoring TestCase class name (just using function name).895 # Maybe we should do this with the AST, or even after the test is896 # imported.897 my_disabled_tests = _disabled_tests_by_file.get(filename, ())898 my_wrapped_tests = _wrapped_tests_by_file.get(filename, {})899 if my_disabled_tests or my_wrapped_tests:900 # Insert our imports early in the file.901 # If we do it on a def-by-def basis, we can break syntax902 # if the function is already decorated903 pattern = r'^import .*'904 replacement = r'from gevent.testing import patched_tests_setup as _GEVENT_PTS;'905 replacement += r'import unittest as _GEVENT_UTS;'906 replacement += r'\g<0>'907 source, n = re.subn(pattern, replacement, source, 1, re.MULTILINE)908 print("Added imports", n)909 # Test cases will always be indented some,910 # so use [ \t]+. Without indentation, test_main, commonly used as the911 # __main__ function at the top level, could get matched. \s matches912 # newlines even in MULTILINE mode so it would still match that.913 my_disabled_testcases = set()914 for test in my_disabled_tests:915 testcase = test.split('.')[-1]916 my_disabled_testcases.add(testcase)917 # def foo_bar(self)918 # ->919 # @_GEVENT_UTS.skip('Removed by patched_tests_setup')920 # def foo_bar(self)921 pattern = r"^([ \t]+)def " + testcase922 replacement = r"\1@_GEVENT_UTS.skip('Removed by patched_tests_setup: %s')\n" % (test,)923 replacement += r"\g<0>"924 source, n = re.subn(pattern, replacement, source, 0, re.MULTILINE)925 print('Skipped %s (%d)' % (testcase, n), file=sys.stderr)926 for test in my_wrapped_tests:927 testcase = test.split('.')[-1]928 if testcase in my_disabled_testcases:929 print("Not wrapping %s because it is skipped" % (test,))930 continue931 # def foo_bar(self)932 # ->933 # @_GEVENT_PTS._PatchedTest('file.Case.name')934 # def foo_bar(self)935 pattern = r"^([ \t]+)def " + testcase936 replacement = r"\1@_GEVENT_PTS._PatchedTest('%s')\n" % (test,)937 replacement += r"\g<0>"938 source, n = re.subn(pattern, replacement, source, 0, re.MULTILINE)939 print('Wrapped %s (%d)' % (testcase, n), file=sys.stderr)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!