test: fix docstring validation function

For some reason in Python even if using getattr with None and as
default value a string for the type __doc__ will return None.

>>> type(getattr(None, "__doc__", ""))
<class 'NoneType'>

The error reported was:

ft1.1: neutron.tests.functional.db.test_migrations.TestModelsMigrationsMySQL.test_branchestesttools.testresult.real._StringException: Traceback (most recent call last):
  File "/home/zuul/src/opendev.org/openstack/neutron/neutron/tests/base.py", line 182, in func
    return f(self, *args, **kwargs)
  File "/home/zuul/src/opendev.org/openstack/neutron/neutron/tests/functional/db/test_migrations.py", line 302, in test_branches
    find_migration_exceptions()
  File "/home/zuul/src/opendev.org/openstack/neutron/neutron/tests/functional/db/test_migrations.py", line 253, in find_migration_exceptions
    if len(explanation) < 1:
TypeError: object of type 'NoneType' has no len()

Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@industrialdiscipline.com>
Change-Id: I7c03bac9c6e8dd074325f511e555c10fec8e77fc
This commit is contained in:
Sahid Orentino Ferdjaoui 2022-11-07 13:17:56 +01:00
parent 562e9704f8
commit 609ebd9504
1 changed files with 1 additions and 1 deletions

View File

@ -250,7 +250,7 @@ class _TestModelsMigrations(test_migrations.ModelsMigrationsSync):
if not get_excepted_elements:
continue
explanation = getattr(get_excepted_elements, '__doc__', "")
if len(explanation) < 1:
if not explanation:
self.fail("%s() requires docstring with explanation" %
'.'.join([m.module.__name__,
get_excepted_elements.__name__]))