Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1236752?usp=email )

Change subject: tests: Add wait cycles between doc tests
......................................................................

tests: Add wait cycles between doc tests

Bug: T414170
Change-Id: I00cd8dd82e46537e019a813c13498df170498933
---
M .github/workflows/doctest.yml
M conftest.py
2 files changed, 56 insertions(+), 2 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/.github/workflows/doctest.yml b/.github/workflows/doctest.yml
index 88300d6..6bc4e1a 100644
--- a/.github/workflows/doctest.yml
+++ b/.github/workflows/doctest.yml
@@ -55,7 +55,7 @@
         run: |
           python pwb.py version
           pytest --version
-          coverage run -m pytest pywikibot --doctest-modules 
--ignore-glob="*gui.py" --ignore-glob="*memento.py"
+          coverage run -m pytest pywikibot --doctest-modules 
--ignore-glob="*gui.py" --ignore-glob="*memento.py" --doctest-wait
       - name: Show coverage statistics
         run: |
           coverage combine || true
diff --git a/conftest.py b/conftest.py
index 544f800..39cc385 100644
--- a/conftest.py
+++ b/conftest.py
@@ -3,16 +3,25 @@
 .. versionadded:: 10.3
 """
 #
-# (C) Pywikibot team, 2025
+# (C) Pywikibot team, 2026
 #
 # Distributed under the terms of the MIT license.
 #
 from __future__ import annotations

 import re
+import time
 from pathlib import Path
 from typing import Literal
 
+from pywikibot.tools import SPHINX_RUNNING
+
+
+try:
+    import pytest
+except ModuleNotFoundError:
+    pytest = None
+

 EXCLUDE_PATTERN = re.compile(
     r'(?:'
@@ -58,3 +67,48 @@

     return None
     # no cover: stop
+
+
+def pytest_addoption(parser) -> None:
+    """Add CLI option --doctest-wait to pause between doctests.
+
+    If the option is given without parameter, the default value is 0.5
+    seconds.
+
+    .. versionadded:: 11.0
+
+    :param parser: The pytest parser object used to add CLI options.
+    :type parser: _pytest.config.argparsing.Parser
+    """
+    parser.addoption(
+        '--doctest-wait',
+        action='store',
+        nargs='?',
+        type=float,
+        const=0.5,
+        default=0.0,
+        help='Pause (seconds) between doctests only. Default is 0.5 s.',
+    )
+
+
+if pytest or SPHINX_RUNNING:
+
+    @pytest.fixture(autouse=True)
+    def pause_between_doctests(request) -> None:
+        """Insert a pause after each doctest if enabled.
+
+        .. versionadded:: 11.0
+
+        :param request: The pytest FixtureRequest object providing test
+            context.
+        :type request: _pytest.fixtures.FixtureRequest
+        """
+        # Handle Doctests only
+        if type(request.node).__name__ != 'DoctestItem':
+            yield
+            return
+
+        yield
+        wait_time = request.config.getoption('--doctest-wait')
+        if wait_time > 0:
+            time.sleep(wait_time)

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1236752?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I00cd8dd82e46537e019a813c13498df170498933
Gerrit-Change-Number: 1236752
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to