Skip to content

Remove pytest_plugin #10762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 45 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b2187ea
Remove pytest_plugin
Dreamsorcerer Apr 20, 2025
9618fe0
Add to lint requirements too
Dreamsorcerer Apr 20, 2025
c73a8bc
Merge branch 'master' into drop-pytest-plugin
bdraco Apr 21, 2025
e0e1a5f
recompile
bdraco Apr 22, 2025
3ac806b
Merge branch 'master' into drop-pytest-plugin
bdraco Apr 22, 2025
1c4dbb0
Update conftest.py
Dreamsorcerer Apr 22, 2025
b9a3723
Rename loop to event_loop
Dreamsorcerer Apr 22, 2025
e336f0e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 22, 2025
d213299
Rename variables to event_loop
Dreamsorcerer Apr 22, 2025
c08b15e
Merge branch 'drop-pytest-plugin' of github.com:aio-libs/aiohttp into…
Dreamsorcerer Apr 22, 2025
3f59011
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 22, 2025
f7d0114
Fix
Dreamsorcerer Apr 22, 2025
19520c3
Merge branch 'drop-pytest-plugin' of github.com:aio-libs/aiohttp into…
Dreamsorcerer Apr 22, 2025
f27bf61
Fix
Dreamsorcerer Apr 22, 2025
bf40464
Fix
Dreamsorcerer Apr 22, 2025
13bef44
Fix
Dreamsorcerer Apr 22, 2025
b21dead
Fix
Dreamsorcerer Apr 22, 2025
cf4a292
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 22, 2025
c3649e2
Fix
Dreamsorcerer Apr 22, 2025
f789ab0
Merge branch 'drop-pytest-plugin' of github.com:aio-libs/aiohttp into…
Dreamsorcerer Apr 22, 2025
6cef9ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 22, 2025
c8bb29c
Update conftest.py
Dreamsorcerer Apr 22, 2025
6847e95
Fix type
Dreamsorcerer Apr 22, 2025
3c9f8cf
Update setup.cfg
Dreamsorcerer Apr 22, 2025
feeb6d0
Fix
Dreamsorcerer Apr 22, 2025
7ca78e8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 22, 2025
ff0b7b6
Fix
Dreamsorcerer Apr 23, 2025
179b945
Merge branch 'drop-pytest-plugin' of github.com:aio-libs/aiohttp into…
Dreamsorcerer Apr 23, 2025
2e5036c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 23, 2025
36d8590
Fix
Dreamsorcerer Apr 23, 2025
fde89ab
Fix
Dreamsorcerer Apr 23, 2025
bb39572
Fix
Dreamsorcerer Apr 23, 2025
4d4cf08
Fix
Dreamsorcerer Apr 23, 2025
a941003
Fix
Dreamsorcerer Apr 24, 2025
cac7a7a
Remove old fixtures
Dreamsorcerer Apr 24, 2025
a2dfcdf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 24, 2025
f4e3f05
Fix
Dreamsorcerer Apr 24, 2025
3a63a8a
Merge branch 'drop-pytest-plugin' of github.com:aio-libs/aiohttp into…
Dreamsorcerer Apr 24, 2025
7316165
Fix
Dreamsorcerer Apr 24, 2025
5fd8d88
Fix
Dreamsorcerer Apr 24, 2025
2e32242
Revert test
Dreamsorcerer Apr 24, 2025
4dcafa3
Fix
Dreamsorcerer Apr 24, 2025
0d113a6
Update tests/test_connector.py
Dreamsorcerer Apr 24, 2025
ed21262
Merge branch 'master' into drop-pytest-plugin
Dreamsorcerer Apr 24, 2025
f1f3a76
Disable xdist
Dreamsorcerer Apr 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
441 changes: 0 additions & 441 deletions aiohttp/pytest_plugin.py

This file was deleted.

50 changes: 0 additions & 50 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ def get_port_socket(
return s


def unused_port() -> int:
"""Return a port that is unused on the current host."""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("127.0.0.1", 0))
return cast(int, s.getsockname()[1])


class BaseTestServer(ABC, Generic[_Request]):
__test__ = False

Expand Down Expand Up @@ -533,49 +526,6 @@ async def get_client(self, server: TestServer) -> TestClient[Request, Applicatio
return TestClient(server)


_LOOP_FACTORY = Callable[[], asyncio.AbstractEventLoop]


@contextlib.contextmanager
def loop_context(
loop_factory: _LOOP_FACTORY = asyncio.new_event_loop, fast: bool = False
) -> Iterator[asyncio.AbstractEventLoop]:
"""A contextmanager that creates an event_loop, for test purposes.

Handles the creation and cleanup of a test loop.
"""
loop = setup_test_loop(loop_factory)
yield loop
teardown_test_loop(loop, fast=fast)


def setup_test_loop(
loop_factory: _LOOP_FACTORY = asyncio.new_event_loop,
) -> asyncio.AbstractEventLoop:
"""Create and return an asyncio.BaseEventLoop instance.

The caller should also call teardown_test_loop,
once they are done with the loop.
"""
loop = loop_factory()
asyncio.set_event_loop(loop)
return loop


def teardown_test_loop(loop: asyncio.AbstractEventLoop, fast: bool = False) -> None:
"""Teardown and cleanup an event_loop created by setup_test_loop."""
closed = loop.is_closed()
if not closed:
loop.call_soon(loop.stop)
loop.run_forever()
loop.close()

if not fast:
gc.collect()

asyncio.set_event_loop(None)


def _create_app_mock() -> mock.MagicMock:
def get_dict(app: Any, key: str) -> Any:
return app.__app_dict[key]
Expand Down
61 changes: 0 additions & 61 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ For using pytest plugin please install pytest-aiohttp_ library:

$ pip install pytest-aiohttp

If you don't want to install *pytest-aiohttp* for some reason you may
insert ``pytest_plugins = 'aiohttp.pytest_plugin'`` line into
``conftest.py`` instead for the same functionality.



The Test Client and Servers
Expand Down Expand Up @@ -206,22 +202,6 @@ Pytest tooling has the following fixtures:

.. versionadded:: 3.0

.. data:: aiohttp_unused_port()

Function to return an unused port number for IPv4 TCP protocol::

async def test_f(aiohttp_client, aiohttp_unused_port):
port = aiohttp_unused_port()
app = web.Application()
# fill route table

client = await aiohttp_client(app, server_kwargs={'port': port})
...

.. versionchanged:: 3.0

The fixture was renamed from ``unused_port`` to ``aiohttp_unused_port``.

.. data:: aiohttp_client_cls

A fixture for passing custom :class:`~aiohttp.test_utils.TestClient` implementations::
Expand Down Expand Up @@ -812,47 +792,6 @@ Utilities
*return_value* when called.


.. function:: unused_port()

Return an unused port number for IPv4 TCP protocol.

:return int: ephemeral port number which could be reused by test server.

.. function:: loop_context(loop_factory=<function asyncio.new_event_loop>)

A contextmanager that creates an event_loop, for test purposes.

Handles the creation and cleanup of a test loop.

.. function:: setup_test_loop(loop_factory=<function asyncio.new_event_loop>)

Create and return an :class:`asyncio.AbstractEventLoop` instance.

The caller should also call teardown_test_loop, once they are done
with the loop.

.. note::

As side effect the function changes asyncio *default loop* by
:func:`asyncio.set_event_loop` call.

Previous default loop is not restored.

It should not be a problem for test suite: every test expects a
new test loop instance anyway.

.. versionchanged:: 3.1

The function installs a created event loop as *default*.

.. function:: teardown_test_loop(loop)

Teardown and cleanup an event_loop created by setup_test_loop.

:param loop: the loop to teardown
:type loop: asyncio.AbstractEventLoop



.. _pytest: http://pytest.org/latest/
.. _pytest-aiohttp: https://pypi.python.org/pypi/pytest-aiohttp
3 changes: 1 addition & 2 deletions examples/fake_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ def __init__(self) -> None:
self.ssl_context.load_cert_chain(str(ssl_cert), str(ssl_key))

async def start(self) -> Dict[str, int]:
port = test_utils.unused_port()
await self.runner.setup()
site = web.TCPSite(self.runner, "127.0.0.1", port, ssl_context=self.ssl_context)
site = web.TCPSite(self.runner, "127.0.0.1", 0, ssl_context=self.ssl_context)
await site.start()
return {"graph.facebook.com": port}

Expand Down
32 changes: 27 additions & 5 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --output-file=requirements/constraints.txt --resolver=backtracking --strip-extras requirements/constraints.in
#
Expand All @@ -9,19 +9,28 @@ aiodns==3.2.0 ; sys_platform == "linux" or sys_platform == "darwin"
# -r requirements/lint.in
# -r requirements/runtime-deps.in
aiohappyeyeballs==2.6.1
# via -r requirements/runtime-deps.in
# via
# -r requirements/runtime-deps.in
# aiohttp
aiohttp==3.11.18
# via pytest-aiohttp
aiohttp-theme==0.1.7
# via -r requirements/doc.in
aiosignal==1.3.2
# via -r requirements/runtime-deps.in
# via
# -r requirements/runtime-deps.in
# aiohttp
alabaster==1.0.0
# via sphinx
annotated-types==0.7.0
# via pydantic
async-timeout==5.0.1 ; python_version < "3.11"
# via
# -r requirements/runtime-deps.in
# aiohttp
# valkey
attrs==25.3.0
# via aiohttp
babel==2.17.0
# via sphinx
blockbuster==1.5.24
Expand Down Expand Up @@ -81,6 +90,7 @@ freezegun==1.5.1
frozenlist==1.6.0
# via
# -r requirements/runtime-deps.in
# aiohttp
# aiosignal
gidgethub==5.3.0
# via cherry-picker
Expand Down Expand Up @@ -117,6 +127,7 @@ multidict==6.4.3
# via
# -r requirements/multidict.in
# -r requirements/runtime-deps.in
# aiohttp
# yarl
mypy==1.15.0 ; implementation_name == "cpython"
# via
Expand Down Expand Up @@ -144,6 +155,7 @@ pre-commit==4.2.0
propcache==0.3.1
# via
# -r requirements/runtime-deps.in
# aiohttp
# yarl
proxy-py==2.4.10
# via
Expand Down Expand Up @@ -175,10 +187,18 @@ pytest==8.1.1
# via
# -r requirements/lint.in
# -r requirements/test.in
# pytest-aiohttp
# pytest-asyncio
# pytest-codspeed
# pytest-cov
# pytest-mock
# pytest-xdist
pytest-aiohttp==1.1.0
# via
# -r requirements/lint.in
# -r requirements/test.in
pytest-asyncio==0.23.8
# via pytest-aiohttp
pytest-codspeed==3.2.0
# via
# -r requirements/lint.in
Expand Down Expand Up @@ -287,7 +307,9 @@ wait-for-it==2.3.0
wheel==0.46.0
# via pip-tools
yarl==1.20.0
# via -r requirements/runtime-deps.in
# via
# -r requirements/runtime-deps.in
# aiohttp
zlib-ng==0.5.1
# via
# -r requirements/lint.in
Expand Down
2 changes: 1 addition & 1 deletion requirements/cython.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with python 3.10
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --output-file=requirements/cython.txt --resolver=backtracking --strip-extras requirements/cython.in
Expand Down
32 changes: 27 additions & 5 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --output-file=requirements/dev.txt --resolver=backtracking --strip-extras requirements/dev.in
#
Expand All @@ -9,19 +9,28 @@ aiodns==3.2.0 ; sys_platform == "linux" or sys_platform == "darwin"
# -r requirements/lint.in
# -r requirements/runtime-deps.in
aiohappyeyeballs==2.6.1
# via -r requirements/runtime-deps.in
# via
# -r requirements/runtime-deps.in
# aiohttp
aiohttp==3.11.18
# via pytest-aiohttp
aiohttp-theme==0.1.7
# via -r requirements/doc.in
aiosignal==1.3.2
# via -r requirements/runtime-deps.in
# via
# -r requirements/runtime-deps.in
# aiohttp
alabaster==1.0.0
# via sphinx
annotated-types==0.7.0
# via pydantic
async-timeout==5.0.1 ; python_version < "3.11"
# via
# -r requirements/runtime-deps.in
# aiohttp
# valkey
attrs==25.3.0
# via aiohttp
babel==2.17.0
# via sphinx
blockbuster==1.5.24
Expand Down Expand Up @@ -79,6 +88,7 @@ freezegun==1.5.1
frozenlist==1.6.0
# via
# -r requirements/runtime-deps.in
# aiohttp
# aiosignal
gidgethub==5.3.0
# via cherry-picker
Expand Down Expand Up @@ -114,6 +124,7 @@ mdurl==0.1.2
multidict==6.4.3
# via
# -r requirements/runtime-deps.in
# aiohttp
# yarl
mypy==1.15.0 ; implementation_name == "cpython"
# via
Expand Down Expand Up @@ -141,6 +152,7 @@ pre-commit==4.2.0
propcache==0.3.1
# via
# -r requirements/runtime-deps.in
# aiohttp
# yarl
proxy-py==2.4.10
# via
Expand Down Expand Up @@ -170,10 +182,18 @@ pytest==8.1.1
# via
# -r requirements/lint.in
# -r requirements/test.in
# pytest-aiohttp
# pytest-asyncio
# pytest-codspeed
# pytest-cov
# pytest-mock
# pytest-xdist
pytest-aiohttp==1.1.0
# via
# -r requirements/lint.in
# -r requirements/test.in
pytest-asyncio==0.23.8
# via pytest-aiohttp
pytest-codspeed==3.2.0
# via
# -r requirements/lint.in
Expand Down Expand Up @@ -278,7 +298,9 @@ wait-for-it==2.3.0
wheel==0.46.0
# via pip-tools
yarl==1.20.0
# via -r requirements/runtime-deps.in
# via
# -r requirements/runtime-deps.in
# aiohttp
zlib-ng==0.5.1
# via
# -r requirements/lint.in
Expand Down
4 changes: 2 additions & 2 deletions requirements/doc.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --output-file=requirements/doc.txt --resolver=backtracking --strip-extras requirements/doc.in
#
Expand Down
1 change: 1 addition & 0 deletions requirements/lint.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mypy; implementation_name == "cpython"
pre-commit
proxy.py
pytest
pytest-aiohttp
pytest-mock
pytest_codspeed
python-on-whales
Expand Down
Loading
Loading