Move 3.11 tests to install aiohttp without C extensions (#3258)

* Move 311 tests to install aiohttp without C extensions

- Configure tox to install aiohttp without extensions
  - i.e. use `AIOHTTP_NO_EXTENSIONS=1` for pip install
  - This allows us to reenable blackd tests that use aiohttp testing helpers etc.
- Had to ignore `cgi` module deprecation warning
  - Filed issue for aiohttp to fix: https://github.com/aio-libs/aiohttp/issues/6905

Test:
- `/tmp/tb/bin/tox -e 311`

* Fix formatting + linting

* Add latest aiohttp for loop fix + Try to exempt deprecation warning but failed - will ask for help

* Remove unnecessary warning ignore

Co-authored-by: Cooper Ry Lees <me@wcooperlees.com>
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
This commit is contained in:
Cooper Lees 2022-09-06 08:27:39 +10:00 committed by GitHub
parent 062e644aae
commit 383b228a16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 193 additions and 189 deletions

View File

@ -1,4 +1,4 @@
name: Partially test 3.11 dev
name: Test 3.11 without aiohttp extensions
on:
push:

View File

@ -111,4 +111,7 @@ filterwarnings = [
# this is mitigated by https://github.com/python/cpython/issues/79071 in python 3.8+
# this ignore can be removed when support for 3.7 is dropped.
'''ignore:Bare functions are deprecated, use async ones:DeprecationWarning''',
# aiohttp is using deprecated cgi modules - Safe to remove when fixed:
# https://github.com/aio-libs/aiohttp/issues/6905
'''ignore:'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning''',
]

View File

@ -1,5 +1,4 @@
import re
import sys
from typing import TYPE_CHECKING, Any, Callable, TypeVar
from unittest.mock import patch
@ -8,22 +7,19 @@
from tests.util import DETERMINISTIC_HEADER, read_data
LESS_THAN_311 = sys.version_info < (3, 11)
if LESS_THAN_311: # noqa: C901
try:
try:
from aiohttp import web
from aiohttp.test_utils import AioHTTPTestCase
import blackd
except ImportError as e:
except ImportError as e:
raise RuntimeError("Please install Black with the 'd' extra") from e
if TYPE_CHECKING:
if TYPE_CHECKING:
F = TypeVar("F", bound=Callable[..., Any])
unittest_run_loop: Callable[[F], F] = lambda x: x
else:
else:
try:
from aiohttp.test_utils import unittest_run_loop
except ImportError:
@ -33,8 +29,9 @@
def unittest_run_loop(func, *args, **kwargs):
return func
@pytest.mark.blackd
class BlackDTestCase(AioHTTPTestCase): # type: ignore[misc]
@pytest.mark.blackd
class BlackDTestCase(AioHTTPTestCase): # type: ignore[misc]
def test_blackd_main(self) -> None:
with patch("blackd.web.run_app"):
result = CliRunner().invoke(blackd.main, [])

View File

@ -51,16 +51,20 @@ commands =
coverage report
[testenv:{,ci-}311]
setenv = PYTHONPATH = {toxinidir}/src
setenv =
PYTHONPATH = {toxinidir}/src
AIOHTTP_NO_EXTENSIONS = 1
skip_install = True
recreate = True
deps =
; We currently need > aiohttp 3.8.1 that is on PyPI for 3.11
git+https://github.com/aio-libs/aiohttp
-r{toxinidir}/test_requirements.txt
; a separate worker is required in ci due to https://foss.heptapod.net/pypy/pypy/-/issues/3317
; this seems to cause tox to wait forever
; remove this when pypy releases the bugfix
commands =
pip install -e .
pip install -e .[d]
coverage erase
pytest tests \
--run-optional no_jupyter \