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.

classification
Title: unit tests rather light on testing __import__(..., level)
Type: behavior Stage: test needed
Components: Tests Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, eric.araujo, ncoghlan, vdupras
Priority: normal Keywords: needs review, patch

Created on 2010-04-14 00:03 by skip.montanaro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ti.diff skip.montanaro, 2010-04-14 12:52
issue8392.diff vdupras, 2010-07-23 11:13
Messages (11)
msg103102 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2010-04-14 00:03
At work we are in the process of migrating from Python 2.4 to 2.6.  One
bit of Boost.Python code needs to use PyImport_ImportModuleLevel which
references the __import__ docs.  That describes the use of the level arg.
I then went around looking for examples and didn't find much, certainly not in the Lib/test directory.  I only saw a couple examples which used
level and they both use level=0, so don't test relative imports or
level=-1.

I don't know that I have enough knowledge of how this stuff is supposed
to work, but will give it a shot.
msg103124 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2010-04-14 12:52
The attached diff adds a PackageTest class which exercises
both "from . import blah" and its __import__() equivalent.
The diff is against the release26-maint branch but I 
suspect it will apply cleanly to trunk and probably py3k.
msg103125 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2010-04-14 12:56
Unassigning so someone else can pick it up and review to
see if this makes sense.
msg103147 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-04-14 21:20
Adding Brett and Nick to nosy, per Misc/maintainers.rst

(Disclaimer: I’m new to issue triaging, tell me if I do something wrong.)

Regards
msg103150 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-04-14 21:37
Yep, this is the right sort of thing to kick in our direction.

There's a reasonable amount of implicit testing of import's level argument through the relative import tests in test_import and test_runpy, but some explicit tests of direct invocation can't hurt.

As Skip says, the test suite can serve as useful example code, although I couldn't recommend that it *all* be treated that way - we do some pretty weird stuff at times in an effort to stress the code under test or to isolate test cases from each other.
msg111263 - (view) Author: Virgil Dupras (vdupras) (Python triager) Date: 2010-07-23 10:14
If I understand the patch correctly, this patch basically add a test for relative imports. I'm pretty sure this is already testes in importlib.test. Brett, am I right?

If yes, there's no point in applying this patch.
msg111265 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2010-07-23 10:23
Yes, importlib has tests for relative import, but those are only run against importlib and not __import__. Adding Skip's tests and seeing how they differ from what importlib.test.import_.test_relative_imports would be good.
msg111276 - (view) Author: Virgil Dupras (vdupras) (Python triager) Date: 2010-07-23 11:13
Because importlib is already well tested and that it already has the machinery to test __import__ instead of the importlib code, I suggest that we re-use importlib's relative tests instead.

Attached is a patch that does this. I made sure that __import__ was actually called.
msg111323 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2010-07-23 14:04
Committed in r83090. Tweaked the patch from Virgil slightly so that it sets the flag used by importlib to delineate whether to use __import__ back to its original setting after running the tests.
msg111325 - (view) Author: Virgil Dupras (vdupras) (Python triager) Date: 2010-07-23 14:11
Brett, I think there's a problem with the tweak you made to the patch. There was already a testcase called RelativeImportTests and you've hidden it (that I why I called it ImportlibRelativeImportTests initially).
msg111339 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2010-07-23 14:48
Fixed in r83091.
History
Date User Action Args
2022-04-11 14:56:59adminsetgithub: 52639
2010-07-23 14:48:24brett.cannonsetmessages: + msg111339
2010-07-23 14:11:34vduprassetmessages: + msg111325
2010-07-23 14:04:58brett.cannonsetstatus: open -> closed
resolution: accepted
messages: + msg111323
2010-07-23 11:13:37vduprassetfiles: + issue8392.diff

messages: + msg111276
2010-07-23 10:23:39brett.cannonsetmessages: + msg111265
2010-07-23 10:14:53vduprassetnosy: + vdupras
messages: + msg111263
2010-05-20 20:40:12skip.montanarosetnosy: - skip.montanaro
2010-04-14 21:37:21ncoghlansetmessages: + msg103150
2010-04-14 21:20:46eric.araujosetnosy: + eric.araujo, brett.cannon, ncoghlan
messages: + msg103147

keywords: + needs review
type: behavior
2010-04-14 12:56:04skip.montanarosetassignee: skip.montanaro ->
messages: + msg103125
2010-04-14 12:52:42skip.montanarosetfiles: + ti.diff
keywords: + patch
messages: + msg103124
2010-04-14 00:03:30skip.montanarocreate