Repository: delfick/alt-pytest-asyncio (language: python)

Issue:
`default_async_timeout` ini file option seemed to stop working in 0.9.0
The command-line option still works, but the ini file option appears to have stopped working. Was that intentional or a bug? I didn't see anything about it in the changelog.


Discussion / hints:
that would indeed be a bug, I'll look into that when I have time if you don't get there first :)
maybe this line
https://github.com/delfick/alt-pytest-asyncio/blob/938e0cbdabc206a6de987b07487234c29c4880e6/alt_pytest_asyncio/plugin.py#L182
also needs a call to `pytestconfig.getini("default_async_timeout")`?

here's how it was before the recent changes:
https://github.com/delfick/alt-pytest-asyncio/blob/695f7eb6f47b9a253e21416e6989963ac6b0de7b/alt_pytest_asyncio/async_converters.py#L151-L154
Yeah, I agree that looks exactly correct!

On Sun, 3 Nov 2024, 19:07 Brian Maissy, ***@***.***> wrote:

> maybe this line
>
> https://github.com/delfick/alt-pytest-asyncio/blob/938e0cbdabc206a6de987b07487234c29c4880e6/alt_pytest_asyncio/plugin.py#L182
> also needs a call to pytestconfig.getini("default_async_timeout")?
>
> here's how it was before the recent changes:
>
> https://github.com/delfick/alt-pytest-asyncio/blob/695f7eb6f47b9a253e21416e6989963ac6b0de7b/alt_pytest_asyncio/async_converters.py#L151-L154
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/delfick/alt-pytest-asyncio/issues/21#issuecomment-2453336511>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAA2V5KGHX4IEGQR3XQE5QTZ6XKVLAVCNFSM6AAAAABQ6KTCM2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINJTGMZTMNJRGE>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>


Fix patch:
diff --git a/docs/index.rst b/docs/index.rst
index c30a818..e506e8f 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -25,6 +25,11 @@ generator fixtures.
 Changelog
 ---------
 
+.. _release-0.9.1:
+
+0.9.1 - TBD
+    * Made the plugin take into account pytest.ini for setting the default async timeout
+
 .. _release-0.9.0:
 
 0.9.0 - 20 October 2024


Test patch:
diff --git a/alt_pytest_asyncio/plugin.py b/alt_pytest_asyncio/plugin.py
index 50fb24b..15ba16c 100644
--- a/alt_pytest_asyncio/plugin.py
+++ b/alt_pytest_asyncio/plugin.py
@@ -22,7 +22,7 @@ def pytest_addoption(parser: pytest.Parser) -> None:
         "alt-pytest-asyncio", description="Alternative asyncio pytest plugin options"
     )
     group.addoption("--default-async-timeout", type=float, dest="default_async_timeout", help=desc)
-    parser.addini("default_async_timeout", desc, default=5)
+    parser.addini("default_async_timeout", desc)
 
 
 class _ManagedLoop(contextlib.AbstractContextManager[None]):
@@ -179,9 +179,14 @@ def set_timeout_seconds(self, timeout: float) -> NoReturn:
 
 @pytest.fixture(scope="session")
 def session_default_async_timeout(pytestconfig: pytest.Config) -> float:
-    timeout = pytestconfig.option.default_async_timeout
+    timeout = pytestconfig.getini("default_async_timeout")
+
+    if not timeout:
+        timeout = pytestconfig.option.default_async_timeout
+
     if timeout is None:
         timeout = 5
+
     return float(timeout)
 
 
diff --git a/helpers/alt_pytest_asyncio_test_driver/examples/example_cli_timeout/__init__.py b/helpers/alt_pytest_asyncio_test_driver/examples/example_cli_timeout/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/helpers/alt_pytest_asyncio_test_driver/examples/example_cli_timeout/expected b/helpers/alt_pytest_asyncio_test_driver/examples/example_cli_timeout/expected
new file mode 100644
index 0000000..843ab7a
--- /dev/null
+++ b/helpers/alt_pytest_asyncio_test_driver/examples/example_cli_timeout/expected
@@ -0,0 +1,5 @@
+=======* FAILURES ====*
+_______* test_outside_cli_timeout ____*
+E   AssertionError: Took too long to complete: */example_cli_timeout/test_timeouts.py:13 (timeout=0.09)
+=======* short test summary info ====*
+=======* 1 failed, 1 passed in * ====*
diff --git a/helpers/alt_pytest_asyncio_test_driver/examples/example_cli_timeout/test_timeouts.py b/helpers/alt_pytest_asyncio_test_driver/examples/example_cli_timeout/test_timeouts.py
new file mode 100644
index 0000000..d468cb8
--- /dev/null
+++ b/helpers/alt_pytest_asyncio_test_driver/examples/example_cli_timeout/test_timeouts.py
@@ -0,0 +1,14 @@
+import asyncio
+
+import alt_pytest_asyncio
+
+AsyncTimeout = alt_pytest_asyncio.protocols.AsyncTimeout
+
+
+async def test_within_cli_timeout(async_timeout: AsyncTimeout) -> None:
+    await asyncio.sleep(0.03)
+
+
+# Note that there is a bit in the tests_examples.py that sets the timeout with the cli
+async def test_outside_cli_timeout(async_timeout: AsyncTimeout) -> None:
+    await asyncio.sleep(0.1)
diff --git a/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/__init__.py b/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/expected b/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/expected
new file mode 100644
index 0000000..29a370f
--- /dev/null
+++ b/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/expected
@@ -0,0 +1,5 @@
+=======* FAILURES ====*
+_______* test_outside_ini_timeout ____*
+E   AssertionError: Took too long to complete: */example_ini_timeout/test_timeouts.py:12 (timeout=0.07)
+=======* short test summary info ====*
+=======* 1 failed, 1 passed in * ====*
diff --git a/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/pytest.ini b/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/pytest.ini
new file mode 100644
index 0000000..56f903c
--- /dev/null
+++ b/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/pytest.ini
@@ -0,0 +1,2 @@
+[pytest]
+default_async_timeout = 0.07
diff --git a/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/test_timeouts.py b/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/test_timeouts.py
new file mode 100644
index 0000000..27a3ce9
--- /dev/null
+++ b/helpers/alt_pytest_asyncio_test_driver/examples/example_ini_timeout/test_timeouts.py
@@ -0,0 +1,13 @@
+import asyncio
+
+import alt_pytest_asyncio
+
+AsyncTimeout = alt_pytest_asyncio.protocols.AsyncTimeout
+
+
+async def test_within_ini_timeout(async_timeout: AsyncTimeout) -> None:
+    await asyncio.sleep(0.03)
+
+
+async def test_outside_ini_timeout(async_timeout: AsyncTimeout) -> None:
+    await asyncio.sleep(0.1)
diff --git a/tests/test_examples.py b/tests/test_examples.py
index 08c65b1..f00ccf5 100644
--- a/tests/test_examples.py
+++ b/tests/test_examples.py
@@ -81,7 +81,16 @@ async def test_shows_correctly_for_failing_fixtures(name: str, pytester: pytest.
     with importlib.resources.as_file(examples) as examples_path:
         shutil.copytree(examples_path, pytester.path / name)
 
-    result = pytester.runpytest_subprocess("--tb", "short", "-p", "alt_pytest_asyncio.enable")
+    if (pytester.path / name / "pytest.ini").exists():
+        (pytester.path / name / "pytest.ini").rename(pytester.path / "pytest.ini")
+
+    timeout_args: list[str] = []
+    if name == "example_cli_timeout":
+        timeout_args.extend(["--default-async-timeout", "0.09"])
+
+    result = pytester.runpytest_subprocess(
+        "--tb", "short", "-p", "alt_pytest_asyncio.enable", *timeout_args
+    )
     assert not result.errlines
 
     lines: int | list[str] = 0