This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aeros
Recipients aeros, brett.cannon, eric.snow, ncoghlan, serhiy.storchaka
Date 2019-08-20.23:49:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1566344957.66.0.473955431282.issue37890@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-08-20 23:49:17aerossetrecipients: + aeros, brett.cannon, ncoghlan, eric.snow, serhiy.storchaka
2019-08-20 23:49:17aerossetmessageid: <1566344957.66.0.473955431282.issue37890@roundup.psfhosted.org>
2019-08-20 23:49:17aeroslinkissue37890 messages
2019-08-20 23:49:17aeroscreate