Skip to content

Commit

Permalink
Fix PyPy datetime mock issue and extension test issue
Browse files Browse the repository at this point in the history
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: celery/celery#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
  • Loading branch information
webknjaz authored Jun 14, 2018
1 parent 7e0075f commit 798c7bd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ jobs:
fast_finish: true
allow_failures:
- python: nightly
- python: *pypy3

include:
- <<: *_doc_base
Expand Down
32 changes: 30 additions & 2 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import gc
import os
import platform
import tempfile
from unittest import mock

Expand All @@ -12,6 +13,9 @@
from aiohttp.abc import AbstractAccessLogger


IS_PYPY = platform.python_implementation() == 'PyPy'


# ------------------- parse_mimetype ----------------------------------

@pytest.mark.parametrize('mimetype, expected', [
Expand Down Expand Up @@ -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__
<class 'unittest.mock.MagicMock'>
(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")
Expand Down Expand Up @@ -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() ----------------------

Expand Down
13 changes: 12 additions & 1 deletion tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import platform
import sys

import pytest
Expand All @@ -10,6 +12,9 @@
'''


IS_PYPY = platform.python_implementation() == 'PyPy'


def test_aiohttp_plugin(testdir):
testdir.makepyfile("""\
import pytest
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 798c7bd

Please sign in to comment.