From: Joseph Sutton Date: Thu, 25 May 2023 05:03:48 +0000 (+1200) Subject: python:tests: Ensure that we don’t overwrite tests X-Git-Tag: talloc-2.4.1~526 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fb759809f89d8277542b1106d39939f32a04778e;p=thirdparty%2Fsamba.git python:tests: Ensure that we don’t overwrite tests If the file iterator returns two entries with the same name, one may overwrite the other. script_iterator() currently ensures this won’t happen, but it pays to be safe. Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/usage.py b/python/samba/tests/usage.py index c75f18cb43b..8441ea03b73 100644 --- a/python/samba/tests/usage.py +++ b/python/samba/tests/usage.py @@ -255,7 +255,10 @@ class PythonScriptUsageTests(TestCase): self.assertIn('usage', out.lower() + err.lower(), 'stdout:\n%s\nstderr:\n%s' % (out, err)) - setattr(cls, 'test_%s' % name, _f) + attr = 'test_%s' % name + if hasattr(cls, attr): + raise RuntimeError(f'Usage test ‘{attr}’ already exists!') + setattr(cls, attr, _f) class HelpTestSuper(TestCase): @@ -344,7 +347,10 @@ class HelpTestSuper(TestCase): if self.check_multiline: self.assertIn('\n', out, 'expected multi-line output') - setattr(cls, 'test_%s' % name, _f) + attr = 'test_%s' % name + if hasattr(cls, attr): + raise RuntimeError(f'Usage test ‘{attr}’ already exists!') + setattr(cls, attr, _f) class PythonScriptHelpTests(HelpTestSuper):