jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1175550?usp=email )

Change subject: Improve execute_pwb to activate coverage only for non-override 
runs
......................................................................

Improve execute_pwb to activate coverage only for non-override runs

- Activate coverage measurement by prepending `-m coverage run` only
  when executing the main pwb.py script (i.e., in the else branch).
- Skip coverage wrapping when running inline Python code with `-c`
  (overrides), as coverage module does not support this usage.
- Use environment variable PYWIKIBOT_TEST_RUNNING to toggle coverage
  activation during test runs.
- Suppress ModuleNotFoundError if coverage is not installed to keep
  fallback clean.

Also update GitHub Actions to skip coverage combine errors by adding
`|| true` to the coverage combine command, preventing job failures
when there are no coverage files to combine.

Bug: T401124
Change-Id: Ib05eba28351107e5626260a976122d3fa076da21
---
M .github/workflows/doctest.yml
M .github/workflows/login_tests-ci.yml
M .github/workflows/oauth_tests-ci.yml
M .github/workflows/pywikibot-ci.yml
M .github/workflows/sysop_write_tests-ci.yml
M .github/workflows/windows_tests.yml
M tests/utils.py
7 files changed, 12 insertions(+), 12 deletions(-)

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




diff --git a/.github/workflows/doctest.yml b/.github/workflows/doctest.yml
index 6c9b8b5..eb55cb6 100644
--- a/.github/workflows/doctest.yml
+++ b/.github/workflows/doctest.yml
@@ -68,7 +68,7 @@
           coverage run -m pytest pywikibot --doctest-modules 
--ignore-glob="*gui.py" --ignore-glob="*memento.py"
       - name: Show coverage statistics
         run: |
-          coverage combine
+          coverage combine || true
           coverage report
       - name: Upload coverage to Codecov
         uses: codecov/codecov-action@v5
diff --git a/.github/workflows/login_tests-ci.yml 
b/.github/workflows/login_tests-ci.yml
index fe66042..835ad56 100644
--- a/.github/workflows/login_tests-ci.yml
+++ b/.github/workflows/login_tests-ci.yml
@@ -124,7 +124,7 @@
           coverage run -m unittest -vv tests/site_login_logout_tests.py
       - name: Show coverage statistics
         run: |
-          coverage combine
+          coverage combine || true
           coverage report
       - name: Upload coverage to Codecov
         uses: codecov/codecov-action@v5
diff --git a/.github/workflows/oauth_tests-ci.yml 
b/.github/workflows/oauth_tests-ci.yml
index 008124b..0d8228c 100644
--- a/.github/workflows/oauth_tests-ci.yml
+++ b/.github/workflows/oauth_tests-ci.yml
@@ -102,7 +102,7 @@
           coverage run -m unittest -vv
       - name: Show coverage statistics
         run: |
-          coverage combine
+          coverage combine || true
           coverage report
       - name: Upload coverage to Codecov
         uses: codecov/codecov-action@v5
diff --git a/.github/workflows/pywikibot-ci.yml 
b/.github/workflows/pywikibot-ci.yml
index dea4499..46f51d8 100644
--- a/.github/workflows/pywikibot-ci.yml
+++ b/.github/workflows/pywikibot-ci.yml
@@ -140,7 +140,7 @@
           fi
       - name: Show coverage statistics
         run: |
-          coverage combine
+          coverage combine || true
           coverage report
       - name: Upload coverage to Codecov
         uses: codecov/codecov-action@v5
diff --git a/.github/workflows/sysop_write_tests-ci.yml 
b/.github/workflows/sysop_write_tests-ci.yml
index 917ba22..b7a1b7d 100644
--- a/.github/workflows/sysop_write_tests-ci.yml
+++ b/.github/workflows/sysop_write_tests-ci.yml
@@ -62,7 +62,7 @@
           coverage run -m pytest -s -r A -a "${{ matrix.attr }}"
       - name: Show coverage statistics
         run: |
-          coverage combine
+          coverage combine || true
           coverage report
       - name: Upload coverage to Codecov
         uses: codecov/codecov-action@v5
diff --git a/.github/workflows/windows_tests.yml 
b/.github/workflows/windows_tests.yml
index 579d45a..95c8aed 100644
--- a/.github/workflows/windows_tests.yml
+++ b/.github/workflows/windows_tests.yml
@@ -75,7 +75,7 @@
           coverage run -m unittest discover -vv -p \"*_tests.py\";
       - name: Show coverage statistics
         run: |
-          coverage combine
+          coverage combine || true
           coverage report
       - name: Upload coverage to Codecov
         uses: codecov/codecov-action@v5
diff --git a/tests/utils.py b/tests/utils.py
index 1c69793..454f41a 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -528,13 +528,13 @@
         command.append(
             f'import pwb; import pywikibot; {overrides}; pwb.main()')
     else:
-        command.append(_pwb_py)
+        # Test is running; activate coverage if present
+        if os.environ.get('PYWIKIBOT_TEST_RUNNING', '0') == '1':
+            with suppress(ModuleNotFoundError):
+                import coverage  # noqa: F401
+                command.extend(['-m', 'coverage', 'run'])

-    # Test is running; activate coverage if present
-    if os.environ.get('PYWIKIBOT_TEST_RUNNING', '0') == '1':
-        with suppress(ModuleNotFoundError):
-            import coverage  # noqa: F401
-            command = [command[0], '-m', 'coverage', 'run'] + command[1:]
+        command.append(_pwb_py)

     return execute(command=command + args, data_in=data_in, timeout=timeout)


--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1175550?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: Ib05eba28351107e5626260a976122d3fa076da21
Gerrit-Change-Number: 1175550
Gerrit-PatchSet: 2
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