Skip to content

Commit

Permalink
refac: black
Browse files Browse the repository at this point in the history
  • Loading branch information
willemt committed Dec 18, 2023
1 parent 847295e commit de98cfb
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 23 deletions.
17 changes: 11 additions & 6 deletions pytest_asyncio_cooperative/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _get_fixture(item, arg_name, fixture=None):
if fixture:
try:
item._request.param = item._pyfuncitem.callspec.params[fixture.argname]
except (AttributeError, KeyError) :
except (AttributeError, KeyError):
pass

return item._request
Expand Down Expand Up @@ -62,16 +62,19 @@ async def fill_fixtures(item):

if fixture.scope not in ["function", "module", "session"]:
raise Exception(f"{fixture.scope} scope not supported")

fixtures.append(fixture)
are_autouse.append(is_autouse)

# Fill fixtures concurrently
fill_results = await asyncio.gather(
*(fill_fixture_fixtures(item._fixtureinfo, fixture, item) for fixture in fixtures)
*(
fill_fixture_fixtures(item._fixtureinfo, fixture, item)
for fixture in fixtures
)
)

for ((value, extra_teardowns), is_autouse) in zip(fill_results, are_autouse):
for (value, extra_teardowns), is_autouse in zip(fill_results, are_autouse):
teardowns.extend(extra_teardowns)

if not is_autouse:
Expand Down Expand Up @@ -373,7 +376,9 @@ async def fill_fixture_fixtures(_fixtureinfo, fixture, item):
):
return await _make_coroutine_fixture(_fixtureinfo, fixture, item)

elif inspect.isgeneratorfunction(fixture.func) or isinstance(fixture.func, CachedGen):
elif inspect.isgeneratorfunction(fixture.func) or isinstance(
fixture.func, CachedGen
):
return await _make_regular_generator_fixture(_fixtureinfo, fixture, item)

elif inspect.isfunction(fixture.func):
Expand Down
4 changes: 3 additions & 1 deletion pytest_asyncio_cooperative/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ async def run_tests(tasks, max_tasks: int):

time_to_wait = (time.time() - earliest_enqueue_time) - task_timeout
done, pending = await asyncio.wait(
tasks, return_when=asyncio.FIRST_COMPLETED, timeout=min(30, int(time_to_wait))
tasks,
return_when=asyncio.FIRST_COMPLETED,
timeout=min(30, int(time_to_wait)),
)

# Cancel tasks that have taken too long
Expand Down
12 changes: 8 additions & 4 deletions tests/test_class_based.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def test_class_based_tests(testdir):
testdir.makepyfile("""
testdir.makepyfile(
"""
import pytest
Expand All @@ -8,15 +9,17 @@ class TestSuite:
async def test_cooperative(self):
assert True
""")
"""
)

result = testdir.runpytest()

result.assert_outcomes(passed=1)


def test_class_based_tests_with_fixture(testdir):
testdir.makepyfile("""
testdir.makepyfile(
"""
import pytest
Expand All @@ -29,7 +32,8 @@ async def test_fixture(self):
async def test_cooperative(self, test_fixture):
assert test_fixture == "test_fixture"
""")
"""
)

result = testdir.runpytest()

Expand Down
18 changes: 11 additions & 7 deletions tests/test_fail.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import pytest


@pytest.mark.parametrize("dur1, dur2, expectedfails, expectedpasses", [
(1.1, 2, 2, 0),
(2, 2, 2, 0),
])
@pytest.mark.parametrize(
"dur1, dur2, expectedfails, expectedpasses",
[
(1.1, 2, 2, 0),
(2, 2, 2, 0),
],
)
def test_function_takes_too_long(testdir, dur1, dur2, expectedfails, expectedpasses):
testdir.makeconftest(
"""""")
testdir.makeconftest("""""")

testdir.makepyfile(
"""
Expand All @@ -22,7 +24,9 @@ async def test_a():
@pytest.mark.asyncio_cooperative
async def test_b():
await asyncio.sleep({})
""".format(dur1, dur2)
""".format(
dur1, dur2
)
)

result = testdir.runpytest("--asyncio-task-timeout", "1")
Expand Down
5 changes: 4 additions & 1 deletion tests/test_fixture.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest


def test_function_fixture(testdir):
testdir.makepyfile(
"""
Expand Down Expand Up @@ -366,7 +367,9 @@ async def test_ordering(ghi, _def, abc):
result.assert_outcomes(passed=1)


def test_ordering_of_fixtures_based_off_function_arguments_with_session_fixture(testdir):
def test_ordering_of_fixtures_based_off_function_arguments_with_session_fixture(
testdir,
):
testdir.makepyfile(
"""
import asyncio
Expand Down
16 changes: 12 additions & 4 deletions tests/test_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ async def test_a():

result = testdir.runpytest()
# FIXME: should be skipped=1
result.assert_outcomes(errors=0, failed=0, passed=0, xfailed=0, xpassed=0, skipped=1)
result.assert_outcomes(
errors=0, failed=0, passed=0, xfailed=0, xpassed=0, skipped=1
)


def test_skipif_is_true(testdir):
Expand All @@ -37,7 +39,9 @@ async def test_a():
)

result = testdir.runpytest()
result.assert_outcomes(errors=0, failed=0, passed=0, xfailed=0, xpassed=0, skipped=1)
result.assert_outcomes(
errors=0, failed=0, passed=0, xfailed=0, xpassed=0, skipped=1
)


def test_skipif_is_false(testdir):
Expand All @@ -58,7 +62,9 @@ async def test_a():
)

result = testdir.runpytest()
result.assert_outcomes(errors=0, failed=0, passed=1, xfailed=0, xpassed=0, skipped=0)
result.assert_outcomes(
errors=0, failed=0, passed=1, xfailed=0, xpassed=0, skipped=0
)


def test_skipif_with_passing(testdir):
Expand Down Expand Up @@ -89,4 +95,6 @@ async def test_3():
)

result = testdir.runpytest()
result.assert_outcomes(errors=0, failed=0, passed=1, xfailed=0, xpassed=0, skipped=2)
result.assert_outcomes(
errors=0, failed=0, passed=1, xfailed=0, xpassed=0, skipped=2
)

0 comments on commit de98cfb

Please sign in to comment.