Skip to content

Commit 13844c0

Browse files
committed
Merge remote-tracking branch 'upstream/master' into async_timeout
2 parents 83d5ad9 + 4c7da65 commit 13844c0

20 files changed

+131
-65
lines changed

.pre-commit-config.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: 'v4.1.0'
4+
hooks:
5+
- id: check-merge-conflict
6+
exclude: "rst$"
7+
- repo: https://github.com/asottile/yesqa
8+
rev: v1.3.0
9+
hooks:
10+
- id: yesqa
11+
- repo: https://github.com/Zac-HD/shed
12+
rev: 0.6.0 # 0.7 does not support Python 3.7
13+
hooks:
14+
- id: shed
15+
args:
16+
- --refactor
17+
- --py37-plus
18+
types_or:
19+
- python
20+
- markdown
21+
- rst
22+
- repo: https://github.com/pre-commit/pre-commit-hooks
23+
rev: v4.1.0
24+
hooks:
25+
- id: trailing-whitespace
26+
- id: end-of-file-fixer
27+
- id: fix-encoding-pragma
28+
args: [--remove]
29+
- id: check-yaml
30+
- id: debug-statements
31+
- repo: https://gitlab.com/pycqa/flake8
32+
rev: 3.9.2
33+
hooks:
34+
- id: flake8
35+
language_version: python3
36+
- repo: https://github.com/pre-commit/pygrep-hooks
37+
rev: v1.9.0
38+
hooks:
39+
- id: python-use-type-annotations

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,3 @@ Apache License
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201201
limitations under the License.
202-

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ clean-test: ## remove test and coverage artifacts
2020
rm -f .coverage
2121
rm -fr htmlcov/
2222

23-
lint: ## check style with flake8
24-
flake8 pytest_asyncio tests
25-
black --check --verbose pytest_asyncio tests
23+
lint:
24+
# CI env-var is set by GitHub actions
25+
ifdef CI
26+
pre-commit run --all-files --show-diff-on-failure
27+
else
28+
pre-commit run --all-files
29+
endif
2630

2731
test:
2832
pytest tests
33+
34+
install:
35+
pip install -U pre-commit
36+
pre-commit install

README.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ provides useful fixtures and markers to make testing easier.
2525
@pytest.mark.asyncio
2626
async def test_some_asyncio_code():
2727
res = await library.do_something()
28-
assert b'expected result' == res
28+
assert b"expected result" == res
2929
3030
pytest-asyncio has been strongly influenced by pytest-tornado_.
3131

@@ -139,9 +139,9 @@ Use ``pytest.mark.asyncio`` for this purpose.
139139
.. code-block:: python
140140
141141
def test_http_client(event_loop):
142-
url = 'http://httpbin.org/get'
142+
url = "http://httpbin.org/get"
143143
resp = event_loop.run_until_complete(http_client(url))
144-
assert b'HTTP/1.1 200 OK' in resp
144+
assert b"HTTP/1.1 200 OK" in resp
145145
146146
This fixture can be easily overridden in any of the standard pytest locations
147147
(e.g. directly in the test file, or in ``conftest.py``) to use a non-default
@@ -189,12 +189,14 @@ Asynchronous fixtures are defined just like ordinary pytest fixtures, except the
189189
190190
import pytest_asyncio
191191
192+
192193
@pytest_asyncio.fixture
193194
async def async_gen_fixture():
194195
await asyncio.sleep(0.1)
195-
yield 'a value'
196+
yield "a value"
197+
196198
197-
@pytest_asyncio.fixture(scope='module')
199+
@pytest_asyncio.fixture(scope="module")
198200
async def async_fixture():
199201
return await asyncio.sleep(0.1)
200202
@@ -227,11 +229,13 @@ Only test coroutines will be affected (by default, coroutines prefixed by
227229
.. code-block:: python
228230
229231
import asyncio
232+
230233
import pytest
231234
232235
# All test coroutines will be treated as marked.
233236
pytestmark = pytest.mark.asyncio
234237
238+
235239
async def test_example(event_loop):
236240
"""No marker!"""
237241
await asyncio.sleep(0, loop=event_loop)
@@ -259,6 +263,7 @@ Changelog
259263
- Fixed an issue when pytest-asyncio was used in combination with `flaky` or inherited asynchronous Hypothesis tests. `#178 <https://github.com/pytest-dev/pytest-asyncio/issues/178>`_ `#231 <https://github.com/pytest-dev/pytest-asyncio/issues/231>`_
260264
- Added `flaky <https://pypi.org/project/flaky/>`_ to test dependencies
261265
- Added ``unused_udp_port`` and ``unused_udp_port_factory`` fixtures (similar to ``unused_tcp_port`` and ``unused_tcp_port_factory`` counterparts. `#99 <https://github.com/pytest-dev/pytest-asyncio/issues/99>`_
266+
- Added the plugin modes: *strict*, *auto*, and *legacy*. See `documentation <https://github.com/pytest-dev/pytest-asyncio#modes>`_ for details. `#125 <https://github.com/pytest-dev/pytest-asyncio/issues/125>`_
262267

263268
0.16.0 (2021-10-16)
264269
~~~~~~~~~~~~~~~~~~~

pytest_asyncio/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33

44
from .plugin import fixture
55

6-
76
__all__ = ("fixture",)

pytest_asyncio/plugin.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import functools
66
import inspect
77
import socket
8-
import sys
98
import warnings
109

1110
import pytest
@@ -17,7 +16,7 @@ class Mode(str, enum.Enum):
1716
LEGACY = "legacy"
1817

1918

20-
LEGACY_MODE = pytest.PytestDeprecationWarning(
19+
LEGACY_MODE = DeprecationWarning(
2120
"The 'asyncio_mode' default value will change to 'strict' in future, "
2221
"please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' "
2322
"in pytest configuration file."
@@ -128,21 +127,7 @@ def pytest_configure(config):
128127
"run using an asyncio event loop",
129128
)
130129
if _get_asyncio_mode(config) == Mode.LEGACY:
131-
_issue_warning_captured(LEGACY_MODE, config.hook, stacklevel=1)
132-
133-
134-
def _issue_warning_captured(warning, hook, *, stacklevel=1):
135-
# copy-paste of pytest internal _pytest.warnings._issue_warning_captured function
136-
with warnings.catch_warnings(record=True) as records:
137-
warnings.simplefilter("always", type(warning))
138-
warnings.warn(LEGACY_MODE, stacklevel=stacklevel)
139-
frame = sys._getframe(stacklevel - 1)
140-
location = frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name
141-
hook.pytest_warning_recorded.call_historic(
142-
kwargs=dict(
143-
warning_message=records[0], when="config", nodeid="", location=location
144-
)
145-
)
130+
config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)
146131

147132

148133
@pytest.mark.tryfirst
@@ -192,7 +177,8 @@ def pytest_fixture_post_finalizer(fixturedef, request):
192177
"""Called after fixture teardown"""
193178
if fixturedef.argname == "event_loop":
194179
policy = asyncio.get_event_loop_policy()
195-
policy.get_event_loop().close() # Clean up existing loop to avoid ResourceWarnings
180+
# Clean up existing loop to avoid ResourceWarnings
181+
policy.get_event_loop().close()
196182
new_loop = policy.new_event_loop() # Replace existing event loop
197183
# Ensure subsequent calls to get_event_loop() succeed
198184
policy.set_event_loop(new_loop)
@@ -240,7 +226,7 @@ def pytest_fixture_setup(fixturedef, request):
240226
)
241227
warnings.warn(
242228
LEGACY_ASYNCIO_FIXTURE.format(name=name),
243-
pytest.PytestDeprecationWarning,
229+
DeprecationWarning,
244230
)
245231
else:
246232
# asyncio_mode is STRICT,
@@ -345,7 +331,8 @@ def pytest_pyfunc_call(pyfuncitem):
345331
"""
346332
Pytest hook called before a test case is run.
347333
348-
Wraps marked tests in a synchronous function where the wrapped test coroutine is executed in an event loop.
334+
Wraps marked tests in a synchronous function
335+
where the wrapped test coroutine is executed in an event loop.
349336
"""
350337
if "asyncio" in pyfuncitem.keywords:
351338
timeout = _get_timeout(pyfuncitem)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ filterwarnings = error
1515
license_file = LICENSE
1616

1717
[flake8]
18-
ignore = E203, E501, W503
18+
max-line-length = 88

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from pathlib import Path
33

4-
from setuptools import setup, find_packages
4+
from setuptools import find_packages, setup
55

66

77
def find_version():

tests/async_fixtures/test_async_fixtures_with_finalizer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def port_finalizer(finalizer):
4646
async def port_afinalizer():
4747
# await task using current loop retrieved from the event loop policy
4848
# RuntimeError is raised if task is created on a different loop.
49-
# This can happen when pytest_fixture_setup does not set up the loop correctly,
49+
# This can happen when pytest_fixture_setup
50+
# does not set up the loop correctly,
5051
# for example when policy.set_event_loop() is called with a wrong argument
5152
await finalizer
5253

tests/hypothesis/test_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import asyncio
55

66
import pytest
7-
87
from hypothesis import given, strategies as st
98

109

0 commit comments

Comments
 (0)