Kyle Stanley <[email protected]> added the comment:
Ah okay, I wasn't sure what exactly would be involved with the "modernization"
process, so those points were just rough ideas more than anything. I haven't
started working on anything yet since I figured it'd be worthwhile to wait for
approval first.
> 1) __import__() can be used for purpose. I would not change this.
Okay, I'll keep that part as is then. This idea was primarily based on
importlib's documentation:
"Programmatic importing of modules should use import_module() instead of
[importlib.__import__()]"
But that probably applies more to users of importlib, rather than the internal
tests for it. That would make sense.
3) How would you distinguish the case when the module have an attribute with
the value is None and when it does not have the attribute at all? This
information would lost with your change.
Good point. This might be a decent way to prevent the AttributeErrors, but
still allows for differentiation of actual None values:
```
try:
self.assertEqual(getattr(module, var), 1)
except AttributeError:
self.fail(f"{module} should have attribute {var}")
```
Personally I think it makes a bit more sense to use self.fail() with a helpful
message rather than raising errors within the tests. There's a comment on line
56, "# self.fail() ?", which gave me this idea. Is there a particular
preference in the context of Python's tests?
Also, do either of you (or anyone else) have any ideas for other modernization
improvements that could be made to either test_pkg_import.py or to the other
two? In the meantime, I can start working on ideas (2) and (4) if those ones
would be appropriate. (2) should be fairly straightforward, but (4) will
probably be a bit more subjective.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue37890>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com