jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/409704 )
Change subject: tox.ini: Ignore or fix newly detected flake8-print errors ......................................................................
tox.ini: Ignore or fix newly detected flake8-print errors
Bug: T186999 Change-Id: I60cbb1e22e7d42f4cbad6ab3a5bc0d154a4da845 --- M tests/__init__.py M tests/aspects.py M tests/script_tests.py M tox.ini 4 files changed, 40 insertions(+), 32 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/__init__.py b/tests/__init__.py index fec9bd3..9291a31 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -193,7 +193,7 @@
def unittest_print(*args, **kwargs): """Print information in test log.""" - print(*args, **kwargs) + print(*args, **kwargs) # noqa: T001
def collector(loader=unittest.loader.defaultTestLoader): @@ -205,16 +205,19 @@ # cause the loader to fallback to its own # discover() ordering of unit tests. if disabled_test_modules: - print('Disabled test modules (to run: python -m unittest ...):\n %s' - % ', '.join(disabled_test_modules)) + unittest_print( + 'Disabled test modules (to run: python -m unittest ...):\n %s' + % ', '.join(disabled_test_modules))
if extra_test_modules: - print('Extra test modules (run after library, before scripts):\n %s' - % ', '.join(extra_test_modules)) + unittest_print( + 'Extra test modules (run after library, before scripts):\n %s' + % ', '.join(extra_test_modules))
if disabled_tests: - print('Skipping tests (to run: python -m unittest ...):\n %r' - % disabled_tests) + unittest_print( + 'Skipping tests (to run: python -m unittest ...):\n %r' + % disabled_tests)
modules = [module for module in test_modules @@ -263,7 +266,8 @@ # frequently in code paths resulting from mishandled server problems. if config.max_retries > 2: if 'PYWIKIBOT_TEST_QUIET' not in os.environ: - print('tests: max_retries reduced from %d to 1' % config.max_retries) + unittest_print( + 'tests: max_retries reduced from %d to 1' % config.max_retries) config.max_retries = 1
cache_misses = 0 diff --git a/tests/aspects.py b/tests/aspects.py index 6d2dfdc..80d7b58 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -51,7 +51,7 @@
import tests
-from tests import unittest, patch_request, unpatch_request +from tests import unittest, patch_request, unpatch_request, unittest_print from tests.utils import ( add_metaclass, execute_pwb, DrySite, DryRequest, WarningSourceSkipContextManager, AssertAPIErrorContextManager, @@ -122,13 +122,13 @@
def _addUnexpectedSuccess(self, result): """Report and ignore.""" - print(' unexpected success ', end='') + unittest_print(' unexpected success ', end='') sys.stdout.flush() result.addSuccess(self)
def _addExpectedFailure(self, result, exc_info=None): """Report and ignore.""" - print(' expected failure ', end='') + unittest_print(' expected failure ', end='') sys.stdout.flush() result.addSuccess(self)
@@ -336,7 +336,7 @@ duration = self.test_completed - self.test_start
if duration > self.test_duration_warning_interval: - print(' %0.3fs' % duration, end=' ') + unittest_print(' %0.3fs' % duration, end=' ') sys.stdout.flush()
super(TestTimerMixin, self).tearDown() @@ -480,9 +480,9 @@ self.cache_hits = tests.cache_hits - self.cache_hits_start
if self.cache_misses: - print(' %d cache misses' % self.cache_misses, end=' ') + unittest_print(' %d cache misses' % self.cache_misses, end=' ') if self.cache_hits: - print(' %d cache hits' % self.cache_hits, end=' ') + unittest_print(' %d cache hits' % self.cache_hits, end=' ')
if self.cache_misses or self.cache_hits: sys.stdout.flush() @@ -1271,8 +1271,9 @@ @param site: site tests should use @type site: BaseSite """ - print('%s using %s instead of %s:%s.' - % (cls.__name__, site, cls.family, cls.code)) + unittest_print( + '{cls.__name__} using {site} instead of {cls.family}:{cls.code}.' + .format(cls=cls, site=site)) cls.site = site cls.family = site.family.name cls.code = site.code diff --git a/tests/script_tests.py b/tests/script_tests.py index 77c516b..647d31e 100644 --- a/tests/script_tests.py +++ b/tests/script_tests.py @@ -16,7 +16,7 @@ StringTypes, )
-from tests import join_root_path +from tests import join_root_path, unittest_print from tests.aspects import (unittest, DefaultSiteTestCase, MetaTestCaseClass, PwbTestCase) from tests.utils import allowed_failure, execute_pwb, add_metaclass @@ -55,8 +55,8 @@ try: __import__(package_name) except ImportError as e: - print('%s depends on %s, which isnt available:\n%s' - % (script_name, package_name, e)) + unittest_print('%s depends on %s, which isnt available:\n%s' + % (script_name, package_name, e)) return False return True
@@ -187,13 +187,13 @@ # discover() ordering of unit tests.
if unrunnable_script_list: - print('Skipping execution of unrunnable scripts:\n %r' - % unrunnable_script_list) + unittest_print('Skipping execution of unrunnable scripts:\n %r' + % unrunnable_script_list)
if not enable_autorun_tests: - print('Skipping execution of auto-run scripts ' - '(set PYWIKIBOT2_TEST_AUTORUN=1 to enable):\n %r' - % auto_run_script_list) + unittest_print('Skipping execution of auto-run scripts ' + '(set PYWIKIBOT2_TEST_AUTORUN=1 to enable):\n %r' + % auto_run_script_list)
tests = (['test__login'] + ['test_' + name @@ -282,10 +282,10 @@ stderr_other = [l for l in stderr if not l.startswith('Sleeping for ')] if stderr_sleep: - print(u'\n'.join(stderr_sleep)) + unittest_print('\n'.join(stderr_sleep))
if result['exit_code'] == -9: - print(' killed', end=' ') + unittest_print(' killed', end=' ')
if error: self.assertIn(error, result['stderr']) @@ -307,14 +307,15 @@ exit_codes = [0, -9]
if (not result['stdout'] and not result['stderr']): - print(' auto-run script unresponsive after %d seconds' - % timeout, end=' ') + unittest_print(' auto-run script unresponsive after ' + '%d seconds' % timeout, end=' ') elif 'SIMULATION: edit action blocked' in result['stderr']: - print(' auto-run script simulated edit blocked', - end=' ') + unittest_print(' auto-run script simulated edit ' + 'blocked', end=' ') else: - print(' auto-run script stderr within %d seconds: %r' - % (timeout, result['stderr']), end=' ') + unittest_print( + ' auto-run script stderr within %d seconds: %r' + % (timeout, result['stderr']), end=' ')
self.assertNotIn('Traceback (most recent call last)', result['stderr']) diff --git a/tox.ini b/tox.ini index df335af..e9fb353 100644 --- a/tox.ini +++ b/tox.ini @@ -200,12 +200,14 @@ scripts/harvest_template.py : T001 scripts/script_wui.py : D102 scripts/makecat.py : D103 + scripts/maintenance/* : T001 scripts/interwiki.py : P102 pywikibot/__init__.py : P103 # pydocstyle cannot handle multiple __all__ variables pywikibot/__init__.py : D999 # valid N805 naming convention exceptions pywikibot/userinterfaces/terminal_interface.py : N814 + tests/pwb/* : T001 # invalidly detected as {} format string: tests/textlib_tests.py : P103 # __dict__ used in a discouraged manner
pywikibot-commits@lists.wikimedia.org