jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1181223?usp=email )
Change subject: Tests: use temporary file for coverage with githun actions only
......................................................................
Tests: use temporary file for coverage with githun actions only
Change-Id: I6314ec03f4b299bfee137affefaf264de34501fe
---
M tests/utils.py
1 file changed, 21 insertions(+), 11 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/utils.py b/tests/utils.py
index 30a9959..3f57ba1 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -517,36 +517,46 @@
the *error* parameter was removed.
.. versionchanged:: 9.1
parameters except *args* are keyword only.
+ .. versionchanged:: 10.4
+ coverage is used if running github actions and a temporary file
+ is used for overrides.
:param args: list of arguments for pwb.py
:param overrides: mapping of pywikibot symbols to test replacements
"""
+ tmp_path: Path | None = None
command = [sys.executable]
+ use_coverage = os.environ.get('GITHUB_ACTIONS') == '1'
- # Test running and coverage is installed, enable coverage with subprocess
- if os.environ.get('PYWIKIBOT_TEST_RUNNING') == '1':
+ if use_coverage:
+ # Test running and coverage is installed,
+ # enable coverage with subprocess
with suppress(ModuleNotFoundError):
import coverage # noqa: F401
command.extend(['-m', 'coverage', 'run', '--parallel-mode'])
- tmp_path: Path | None = None
- try:
- if overrides:
+ if overrides:
+ override_code = 'import pwb, pywikibot\n'
+ override_code += '\n'.join(f'{k} = {v}' for k, v in overrides.items())
+ override_code += '\npwb.main()'
+
+ if use_coverage:
# Write overrides in temporary file
with tempfile.NamedTemporaryFile(
'w', suffix='.py', delete=False) as f:
- f.write('import pwb\nimport pywikibot\n')
- f.write('\n'.join(f'{k} = {v}' for k, v in overrides.items()))
- f.write('\npwb.main()\n')
+ f.write(override_code)
tmp_path = Path(f.name)
- command.append(f.name)
+ command.append(f.name)
else:
- command.append(_pwb_py)
+ command.extend(['-c', override_code])
+ else:
+ command.append(_pwb_py)
+
+ try:
# Run subprocess
result = execute(
command=command + args, data_in=data_in, timeout=timeout)
-
finally:
# delete temporary file if created
if tmp_path and tmp_path.exists():
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1181223?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: I6314ec03f4b299bfee137affefaf264de34501fe
Gerrit-Change-Number: 1181223
Gerrit-PatchSet: 1
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]