From 798c7bdebf19317f8bd1518889a1c8a75a8d3c53 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Thu, 14 Jun 2018 18:03:51 +0300 Subject: [PATCH] Fix PyPy datetime mock issue and extension test issue PR #3083 * Don't test C reify when testing with no extensions * Skip test_access_logger_atoms under PyPy It fails because PyPy, unlike CPython, has pure-python implementation of datetime and when it's patched, it fails on isinstance check in magic methods. Ref: https://bitbucket.org/pypy/pypy/issues/1187/call-to-isinstance-in-__sub__-self-other Ref: https://github.com/celery/celery/issues/811 Ref: https://stackoverflow.com/a/46102240/595220 * Disallow PyPy3 failures * Don't test C-reify under PyPy * Don't run test_warning_checks under PyPy * Expect different outcome for PyPy + ASYNCIODEBUG --- .travis.yml | 1 - tests/test_helpers.py | 32 ++++++++++++++++++++++++++++++-- tests/test_pytest_plugin.py | 13 ++++++++++++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c8a207fc84..ac608fc4c5b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -135,7 +135,6 @@ jobs: fast_finish: true allow_failures: - python: nightly - - python: *pypy3 include: - <<: *_doc_base diff --git a/tests/test_helpers.py b/tests/test_helpers.py index afeb5da0cf3..c3014d004c6 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -2,6 +2,7 @@ import datetime import gc import os +import platform import tempfile from unittest import mock @@ -12,6 +13,9 @@ from aiohttp.abc import AbstractAccessLogger +IS_PYPY = platform.python_implementation() == 'PyPy' + + # ------------------- parse_mimetype ---------------------------------- @pytest.mark.parametrize('mimetype, expected', [ @@ -124,6 +128,29 @@ def test_access_logger_format(): assert expected == access_logger._log_format +@pytest.mark.skip( + IS_PYPY, + """ + Because of patching :py:class:`datetime.datetime`, under PyPy it + fails in :py:func:`isinstance` call in + :py:meth:`datetime.datetime.__sub__` (called from + :py:meth:`aiohttp.helpers.AccessLogger._format_t`): + + *** TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types + + (Pdb) from datetime import datetime + (Pdb) isinstance(now, datetime) + *** TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types + (Pdb) datetime.__class__ + + (Pdb) isinstance(now, datetime.__class__) + False + + Ref: https://bitbucket.org/pypy/pypy/issues/1187/call-to-isinstance-in-__sub__-self-other + Ref: https://github.com/celery/celery/issues/811 + Ref: https://stackoverflow.com/a/46102240/595220 + """, # noqa: E501 +) def test_access_logger_atoms(mocker): utcnow = datetime.datetime(1843, 1, 1, 0, 30) mock_datetime = mocker.patch("aiohttp.helpers.datetime.datetime") @@ -289,8 +316,9 @@ class TestPyReify(ReifyMixin): reify = helpers.reify_py -class TestCReify(ReifyMixin): - reify = helpers.reify_c +if not helpers.NO_EXTENSIONS and not IS_PYPY: + class TestCReify(ReifyMixin): + reify = helpers.reify_c # ----------------------------------- is_ip_address() ---------------------- diff --git a/tests/test_pytest_plugin.py b/tests/test_pytest_plugin.py index 608f361b746..4106cb2a1e1 100644 --- a/tests/test_pytest_plugin.py +++ b/tests/test_pytest_plugin.py @@ -1,3 +1,5 @@ +import os +import platform import sys import pytest @@ -10,6 +12,9 @@ ''' +IS_PYPY = platform.python_implementation() == 'PyPy' + + def test_aiohttp_plugin(testdir): testdir.makepyfile("""\ import pytest @@ -163,7 +168,13 @@ async def test_bad(): testdir.makeconftest(CONFTEST) result = testdir.runpytest('-p', 'no:sugar', '-s', '-W', 'default', '--aiohttp-loop=pyloop') - result.assert_outcomes(passed=1, failed=1) + expected_outcomes = ( + {'failed': 0, 'passed': 2} + if IS_PYPY and bool(os.environ.get('PYTHONASYNCIODEBUG')) + else {'failed': 1, 'passed': 1} + ) + """Under PyPy "coroutine 'foobar' was never awaited" does not happen.""" + result.assert_outcomes(**expected_outcomes) def test_aiohttp_plugin_async_fixture(testdir, capsys):