[issue37890] Modernize several tests in test_importlib
Kyle Stanley
report at bugs.python.org
Tue Aug 20 21:09:47 EDT 2019
Kyle Stanley <aeros167 at gmail.com> added the comment:
> This might be a decent way to prevent the AttributeErrors, but still allows for differentiation of actual None values
Another alternative solution might be to use hasattr() before getattr(), if it is not desirable for test_pkg_import.py to raise exceptions:
```
self.assertTrue(hasattr(module, var), msg=f"{module} should have attribute {var}")
self.assertEqual(getattr(module, var), 1)
```
That would follow more of a LBYL style, but I know that EAFP is more common within Python. The better alternative depends on the answer to my earlier question regarding exceptions being raised from the unit tests:
> Is there a particular preference in the context of Python's tests?
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37890>
_______________________________________
More information about the Python-bugs-list
mailing list