Skip to content

Commit 78ae701

Browse files
committed
Fix bug where the ini configuration isn't respected
Fixes #21
1 parent 938e0cb commit 78ae701

File tree

10 files changed

+61
-3
lines changed

10 files changed

+61
-3
lines changed

alt_pytest_asyncio/plugin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def pytest_addoption(parser: pytest.Parser) -> None:
2222
"alt-pytest-asyncio", description="Alternative asyncio pytest plugin options"
2323
)
2424
group.addoption("--default-async-timeout", type=float, dest="default_async_timeout", help=desc)
25-
parser.addini("default_async_timeout", desc, default=5)
25+
parser.addini("default_async_timeout", desc)
2626

2727

2828
class _ManagedLoop(contextlib.AbstractContextManager[None]):
@@ -179,9 +179,14 @@ def set_timeout_seconds(self, timeout: float) -> NoReturn:
179179

180180
@pytest.fixture(scope="session")
181181
def session_default_async_timeout(pytestconfig: pytest.Config) -> float:
182-
timeout = pytestconfig.option.default_async_timeout
182+
timeout = pytestconfig.getini("default_async_timeout")
183+
184+
if not timeout:
185+
timeout = pytestconfig.option.default_async_timeout
186+
183187
if timeout is None:
184188
timeout = 5
189+
185190
return float(timeout)
186191

187192

docs/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ generator fixtures.
2525
Changelog
2626
---------
2727

28+
.. _release-0.9.1:
29+
30+
0.9.1 - TBD
31+
* Made the plugin take into account pytest.ini for setting the default async timeout
32+
2833
.. _release-0.9.0:
2934

3035
0.9.0 - 20 October 2024

helpers/alt_pytest_asyncio_test_driver/examples/example_cli_timeout/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=======* FAILURES ====*
2+
_______* test_outside_cli_timeout ____*
3+
E AssertionError: Took too long to complete: */example_cli_timeout/test_timeouts.py:13 (timeout=0.09)
4+
=======* short test summary info ====*
5+
=======* 1 failed, 1 passed in * ====*
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import asyncio
2+
3+
import alt_pytest_asyncio
4+
5+
AsyncTimeout = alt_pytest_asyncio.protocols.AsyncTimeout
6+
7+
8+
async def test_within_cli_timeout(async_timeout: AsyncTimeout) -> None:
9+
await asyncio.sleep(0.03)
10+
11+
12+
# Note that there is a bit in the tests_examples.py that sets the timeout with the cli
13+
async def test_outside_cli_timeout(async_timeout: AsyncTimeout) -> None:
14+
await asyncio.sleep(0.1)

helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=======* FAILURES ====*
2+
_______* test_outside_ini_timeout ____*
3+
E AssertionError: Took too long to complete: */example_ini_timeout/test_timeouts.py:12 (timeout=0.07)
4+
=======* short test summary info ====*
5+
=======* 1 failed, 1 passed in * ====*
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
default_async_timeout = 0.07
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import asyncio
2+
3+
import alt_pytest_asyncio
4+
5+
AsyncTimeout = alt_pytest_asyncio.protocols.AsyncTimeout
6+
7+
8+
async def test_within_ini_timeout(async_timeout: AsyncTimeout) -> None:
9+
await asyncio.sleep(0.03)
10+
11+
12+
async def test_outside_ini_timeout(async_timeout: AsyncTimeout) -> None:
13+
await asyncio.sleep(0.1)

tests/test_examples.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,16 @@ async def test_shows_correctly_for_failing_fixtures(name: str, pytester: pytest.
8181
with importlib.resources.as_file(examples) as examples_path:
8282
shutil.copytree(examples_path, pytester.path / name)
8383

84-
result = pytester.runpytest_subprocess("--tb", "short", "-p", "alt_pytest_asyncio.enable")
84+
if (pytester.path / name / "pytest.ini").exists():
85+
(pytester.path / name / "pytest.ini").rename(pytester.path / "pytest.ini")
86+
87+
timeout_args: list[str] = []
88+
if name == "example_cli_timeout":
89+
timeout_args.extend(["--default-async-timeout", "0.09"])
90+
91+
result = pytester.runpytest_subprocess(
92+
"--tb", "short", "-p", "alt_pytest_asyncio.enable", *timeout_args
93+
)
8594
assert not result.errlines
8695

8796
lines: int | list[str] = 0

0 commit comments

Comments
 (0)