[issue37890] Modernize several tests in test_importlib

Kyle Stanley report at bugs.python.org
Mon Aug 19 23:43:42 EDT 2019


Kyle Stanley <aeros167 at gmail.com> added the comment:

I'm not entirely certain as to which parts should be modernized, and which ones can remain the same. A large part of my uncertainty is that there are no header comments for "test_pkg_import.py" to explain the test coverage, so I don't know if there are additional tests beyond the existing ones that should be added.

The first steps I can think of: 

1) Use ``importlib.import_module()`` instead of the built-in ``__import__()``

2) Use ``with self.assertRaises(<exception>, <msg>): ...`` instead of

```
try: __import__(self.module_name)
        except SyntaxError: pass
        else: raise RuntimeError('Failed to induce SyntaxError') # self.fail()?

...
```

3) Replace ``self.assertEqual(getattr(module, var), 1)`` with ``self.assertEqual(getattr(module, var, None), 1)`` so that AttributeErrors are not raised when unexpected behaviors occur

4) Provide useful error messages for failed assertions

I'll begin working on those, probably with a separate PR for each of them for ease of review. Let me know if there's anything else I should do, or if any of the above steps are unneeded. If I think of anything else I'll update the issue accordingly.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37890>
_______________________________________


More information about the Python-bugs-list mailing list