Skip to content

Commit 22d91b2

Browse files
committed
Black linting
1 parent 5c47b78 commit 22d91b2

16 files changed

+71
-42
lines changed

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean clean-build clean-pyc clean-test
1+
.PHONY: clean clean-build clean-pyc clean-test lint
22

33
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
44

@@ -19,3 +19,7 @@ clean-test: ## remove test and coverage artifacts
1919
rm -fr .tox/
2020
rm -f .coverage
2121
rm -fr htmlcov/
22+
23+
lint: ## check style with flake8
24+
flake8 pytest_asyncio tests
25+
black --check --verbose pytest_asyncio tests

README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pytest-asyncio: pytest support for asyncio
1010
.. image:: https://img.shields.io/pypi/pyversions/pytest-asyncio.svg
1111
:target: https://github.com/pytest-dev/pytest-asyncio
1212
:alt: Supported Python versions
13+
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
14+
:target: https://github.com/ambv/black
1315

1416
pytest-asyncio is an Apache2 licensed library, written in Python, for testing
1517
asyncio code with pytest.

pytest_asyncio/plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self, fixturedef):
6262

6363
def add(self, name):
6464
"""Add fixture name to fixturedef
65-
and record in to_strip list (If not previously included)"""
65+
and record in to_strip list (If not previously included)"""
6666
if name in self.fixturedef.argnames:
6767
return
6868
self.fixturedef.argnames += (name,)

setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ filterwarnings = error
1212
[metadata]
1313
# ensure LICENSE is included in wheel metadata
1414
license_file = LICENSE
15+
16+
[flake8]
17+
ignore = E203, E501, W503

tests/async_fixtures/test_async_fixtures_scope.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
module-scoped too.
44
"""
55
import asyncio
6+
67
import pytest
78

89

9-
@pytest.fixture(scope='module')
10+
@pytest.fixture(scope="module")
1011
def event_loop():
1112
"""A module-scoped event loop."""
1213
return asyncio.new_event_loop()
1314

1415

15-
@pytest.fixture(scope='module')
16+
@pytest.fixture(scope="module")
1617
async def async_fixture():
1718
await asyncio.sleep(0.1)
1819
return 1

tests/async_fixtures/test_async_fixtures_with_finalizer.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import functools
3+
34
import pytest
45

56

@@ -8,11 +9,13 @@ async def test_module_with_event_loop_finalizer(port_with_event_loop_finalizer):
89
await asyncio.sleep(0.01)
910
assert port_with_event_loop_finalizer
1011

12+
1113
@pytest.mark.asyncio
1214
async def test_module_with_get_event_loop_finalizer(port_with_get_event_loop_finalizer):
1315
await asyncio.sleep(0.01)
1416
assert port_with_get_event_loop_finalizer
1517

18+
1619
@pytest.fixture(scope="module")
1720
def event_loop():
1821
"""Change event_loop fixture to module level."""
@@ -29,6 +32,7 @@ async def port_afinalizer():
2932
# await task using loop provided by event_loop fixture
3033
# RuntimeError is raised if task is created on a different loop
3134
await finalizer
35+
3236
event_loop.run_until_complete(port_afinalizer())
3337

3438
worker = asyncio.ensure_future(asyncio.sleep(0.2))
@@ -43,6 +47,7 @@ async def port_afinalizer():
4347
# await task using loop provided by asyncio.get_event_loop()
4448
# RuntimeError is raised if task is created on a different loop
4549
await finalizer
50+
4651
asyncio.get_event_loop().run_until_complete(port_afinalizer())
4752

4853
worker = asyncio.ensure_future(asyncio.sleep(0.2))

tests/async_fixtures/test_async_gen_fixtures.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import unittest.mock
32

43
import pytest
@@ -8,7 +7,7 @@
87
RETVAL = object()
98

109

11-
@pytest.fixture(scope='module')
10+
@pytest.fixture(scope="module")
1211
def mock():
1312
return unittest.mock.Mock(return_value=RETVAL)
1413

tests/async_fixtures/test_coroutine_fixtures.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
END = object()
88
RETVAL = object()
99

10-
pytestmark = pytest.mark.skip(reason='@asyncio.coroutine fixtures are not supported yet')
10+
pytestmark = pytest.mark.skip(
11+
reason="@asyncio.coroutine fixtures are not supported yet"
12+
)
1113

1214

1315
@pytest.fixture

tests/async_fixtures/test_nested.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import asyncio
2+
23
import pytest
34

45

56
@pytest.fixture()
67
async def async_inner_fixture():
78
await asyncio.sleep(0.01)
8-
print('inner start')
9+
print("inner start")
910
yield True
10-
print('inner stop')
11+
print("inner stop")
1112

1213

1314
@pytest.fixture()
1415
async def async_fixture_outer(async_inner_fixture, event_loop):
1516
await asyncio.sleep(0.01)
16-
print('outer start')
17+
print("outer start")
1718
assert async_inner_fixture is True
1819
yield True
19-
print('outer stop')
20+
print("outer stop")
2021

2122

2223
@pytest.mark.asyncio
2324
async def test_async_fixture(async_fixture_outer):
2425
assert async_fixture_outer is True
25-
print('test_async_fixture')
26+
print("test_async_fixture")

tests/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ async def just_a_sleep():
2222
assert counter == 2
2323

2424

25-
@pytest.fixture(scope='session', name='factory_involving_factories')
25+
@pytest.fixture(scope="session", name="factory_involving_factories")
2626
def factory_involving_factories_fixture(unused_tcp_port_factory):
2727
def factory():
2828
return unused_tcp_port_factory()
29+
2930
return factory

tests/markers/test_class_marker.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test if pytestmark works when defined on a class."""
22
import asyncio
3+
34
import pytest
45

56

@@ -14,6 +15,7 @@ async def inc():
1415
nonlocal counter
1516
counter += 1
1617
await asyncio.sleep(0)
18+
1719
await asyncio.ensure_future(inc())
1820
assert counter == 2
1921

tests/markers/test_module_marker.py

+2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ async def inc():
2424
async def test_is_asyncio(event_loop, sample_fixture):
2525
assert asyncio.get_event_loop()
2626
counter = 1
27+
2728
async def inc():
2829
nonlocal counter
2930
counter += 1
3031
await asyncio.sleep(0)
32+
3133
await asyncio.ensure_future(inc())
3234
assert counter == 2
3335

tests/multiloop/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
class CustomSelectorLoop(asyncio.SelectorEventLoop):
77
"""A subclass with no overrides, just to test for presence."""
8+
89
pass
910

1011

tests/test_simple.py

+19-24
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
"""Quick'n'dirty unit tests for provided fixtures and markers."""
22
import asyncio
3-
import pytest
43

4+
import pytest
55
import pytest_asyncio.plugin
66

77

88
async def async_coro():
99
await asyncio.sleep(0)
10-
return 'ok'
10+
return "ok"
1111

1212

1313
def test_event_loop_fixture(event_loop):
1414
"""Test the injection of the event_loop fixture."""
1515
assert event_loop
1616
ret = event_loop.run_until_complete(async_coro())
17-
assert ret == 'ok'
17+
assert ret == "ok"
1818

1919

2020
@pytest.mark.asyncio
@@ -23,7 +23,7 @@ async def test_asyncio_marker():
2323
await asyncio.sleep(0)
2424

2525

26-
@pytest.mark.xfail(reason='need a failure', strict=True)
26+
@pytest.mark.xfail(reason="need a failure", strict=True)
2727
@pytest.mark.asyncio
2828
def test_asyncio_marker_fail():
2929
assert False
@@ -42,12 +42,10 @@ async def test_unused_port_fixture(unused_tcp_port, event_loop):
4242
async def closer(_, writer):
4343
writer.close()
4444

45-
server1 = await asyncio.start_server(closer, host='localhost',
46-
port=unused_tcp_port)
45+
server1 = await asyncio.start_server(closer, host="localhost", port=unused_tcp_port)
4746

4847
with pytest.raises(IOError):
49-
await asyncio.start_server(closer, host='localhost',
50-
port=unused_tcp_port)
48+
await asyncio.start_server(closer, host="localhost", port=unused_tcp_port)
5149

5250
server1.close()
5351
await server1.wait_closed()
@@ -60,20 +58,19 @@ async def test_unused_port_factory_fixture(unused_tcp_port_factory, event_loop):
6058
async def closer(_, writer):
6159
writer.close()
6260

63-
port1, port2, port3 = (unused_tcp_port_factory(), unused_tcp_port_factory(),
64-
unused_tcp_port_factory())
61+
port1, port2, port3 = (
62+
unused_tcp_port_factory(),
63+
unused_tcp_port_factory(),
64+
unused_tcp_port_factory(),
65+
)
6566

66-
server1 = await asyncio.start_server(closer, host='localhost',
67-
port=port1)
68-
server2 = await asyncio.start_server(closer, host='localhost',
69-
port=port2)
70-
server3 = await asyncio.start_server(closer, host='localhost',
71-
port=port3)
67+
server1 = await asyncio.start_server(closer, host="localhost", port=port1)
68+
server2 = await asyncio.start_server(closer, host="localhost", port=port2)
69+
server3 = await asyncio.start_server(closer, host="localhost", port=port3)
7270

7371
for port in port1, port2, port3:
7472
with pytest.raises(IOError):
75-
await asyncio.start_server(closer, host='localhost',
76-
port=port)
73+
await asyncio.start_server(closer, host="localhost", port=port)
7774

7875
server1.close()
7976
await server1.wait_closed()
@@ -96,8 +93,7 @@ def mock_unused_tcp_port():
9693
else:
9794
return 10000 + counter
9895

99-
monkeypatch.setattr(pytest_asyncio.plugin, '_unused_tcp_port',
100-
mock_unused_tcp_port)
96+
monkeypatch.setattr(pytest_asyncio.plugin, "_unused_tcp_port", mock_unused_tcp_port)
10197

10298
assert unused_tcp_port_factory() == 10000
10399
assert unused_tcp_port_factory() > 10000
@@ -110,7 +106,7 @@ class Test:
110106
async def test_asyncio_marker_method(self, event_loop):
111107
"""Test the asyncio pytest marker in a Test class."""
112108
ret = await async_coro()
113-
assert ret == 'ok'
109+
assert ret == "ok"
114110

115111

116112
class TestUnexistingLoop:
@@ -125,7 +121,7 @@ def remove_loop(self):
125121
async def test_asyncio_marker_without_loop(self, remove_loop):
126122
"""Test the asyncio pytest marker in a Test class."""
127123
ret = await async_coro()
128-
assert ret == 'ok'
124+
assert ret == "ok"
129125

130126

131127
class TestEventLoopStartedBeforeFixtures:
@@ -150,12 +146,11 @@ async def test_event_loop_before_fixture(self, event_loop, loop):
150146
assert await loop.run_in_executor(None, self.foo) == 1
151147

152148

153-
154149
@pytest.mark.asyncio
155150
async def test_no_warning_on_skip():
156151
pytest.skip("Test a skip error inside asyncio")
157152

158153

159154
def test_async_close_loop(event_loop):
160155
event_loop.close()
161-
return 'ok'
156+
return "ok"

tests/test_subprocess.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"""Tests for using subprocesses in tests."""
2-
import sys
32
import asyncio
43
import asyncio.subprocess
4+
import sys
55

66
import pytest
77

8-
9-
if sys.platform == 'win32':
8+
if sys.platform == "win32":
109
# The default asyncio event loop implementation on Windows does not
1110
# support subprocesses. Subprocesses are available for Windows if a
1211
# ProactorEventLoop is used.
@@ -21,13 +20,15 @@ def event_loop():
2120
async def test_subprocess(event_loop):
2221
"""Starting a subprocess should be possible."""
2322
proc = await asyncio.subprocess.create_subprocess_exec(
24-
sys.executable, '--version', stdout=asyncio.subprocess.PIPE)
23+
sys.executable, "--version", stdout=asyncio.subprocess.PIPE
24+
)
2525
await proc.communicate()
2626

2727

2828
@pytest.mark.asyncio(forbid_global_loop=True)
2929
async def test_subprocess_forbid(event_loop):
3030
"""Starting a subprocess should be possible."""
3131
proc = await asyncio.subprocess.create_subprocess_exec(
32-
sys.executable, '--version', stdout=asyncio.subprocess.PIPE)
32+
sys.executable, "--version", stdout=asyncio.subprocess.PIPE
33+
)
3334
await proc.communicate()

tox.ini

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ skip_missing_interpreters = true
77
extras = testing
88
commands = coverage run -m pytest {posargs}
99

10+
[testenv:lint]
11+
skip_install = true
12+
basepython = python3.9
13+
extras = tests
14+
deps =
15+
flake8
16+
black
17+
commands =
18+
make lint
19+
1020
[testenv:coverage-report]
1121
deps = coverage
1222
skip_install = true

0 commit comments

Comments
 (0)