Skip to content

Commit 4c7da65

Browse files
authored
Setup pre-commit hooks and reformat code (#245)
1 parent 5d4954a commit 4c7da65

19 files changed

+86
-36
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: 9 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)

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def pytest_fixture_post_finalizer(fixturedef, request):
159159
"""Called after fixture teardown"""
160160
if fixturedef.argname == "event_loop":
161161
policy = asyncio.get_event_loop_policy()
162-
policy.get_event_loop().close() # Clean up existing loop to avoid ResourceWarnings
162+
# Clean up existing loop to avoid ResourceWarnings
163+
policy.get_event_loop().close()
163164
new_loop = policy.new_event_loop() # Replace existing event loop
164165
# Ensure subsequent calls to get_event_loop() succeed
165166
policy.set_event_loop(new_loop)
@@ -282,7 +283,8 @@ def pytest_pyfunc_call(pyfuncitem):
282283
"""
283284
Pytest hook called before a test case is run.
284285
285-
Wraps marked tests in a synchronous function where the wrapped test coroutine is executed in an event loop.
286+
Wraps marked tests in a synchronous function
287+
where the wrapped test coroutine is executed in an event loop.
286288
"""
287289
if "asyncio" in pyfuncitem.keywords:
288290
if getattr(pyfuncitem.obj, "is_hypothesis_test", False):

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)