classification
Title: Add test.support.import_python_only
Type: enhancement Stage:
Components: Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: ncoghlan Nosy List: brett.cannon, ncoghlan
Priority: normal Keywords:

Created on 2009-02-23 21:19 by ncoghlan, last changed 2009-04-22 16:14 by ncoghlan. This issue is now closed.

Files
File name Uploaded Description Edit
unnamed brett.cannon, 2009-02-23 22:13
unnamed brett.cannon, 2009-04-11 19:36
Messages (7)
msg82643 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2009-02-23 21:19
Add test.support.import_python_only as per
http://mail.python.org/pipermail/python-dev/2009-February/086387.html

Also add an equivalent to test.test_support in 2.x (I haven't checked
yet if importlib is available in 2.x, so the implementation may need to
be a little different)
msg82647 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-02-23 22:13
On Mon, Feb 23, 2009 at 13:19, Nick Coghlan <report@bugs.python.org> wrote:

>
> New submission from Nick Coghlan <ncoghlan@gmail.com>:
>
> Add test.support.import_python_only as per
> http://mail.python.org/pipermail/python-dev/2009-February/086387.html
>
> Also add an equivalent to test.test_support in 2.x (I haven't checked
> yet if importlib is available in 2.x, so the implementation may need to
> be a little different)

Importlib is in 2.7.
msg85861 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2009-04-11 14:25
Ended up going for a slightly more general name "import_fresh_module".
Reason being, test_warnings *also* wanted a fresh version of the
accelerated module along with a pure Python version - it seemed silly to
only factor out half of the problem into a support function, when the
support function could handle both tasks fairly easily.

So I implemented a version of the fresh import function that blocks no
extension modules by default, but still accepts a list of names to be
disabled during the import.
msg85863 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2009-04-11 14:31
Implemented for 2.7 in r71465
Implemented for 3.1 in r71469

Leaving issue open for the moment - the 3.1 test_warnings fails if I
don't get a fresh copy of _warnings before running the unit tests. I
want to figure out why that is necessary before closing the issue.
msg85872 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-04-11 19:36
On Sat, Apr 11, 2009 at 07:28, Nick Coghlan <report@bugs.python.org> wrote:

>
> Nick Coghlan <ncoghlan@gmail.com> added the comment:
>
> Implemented for 2.7 in r71465
> Implemented for 3.1 in r7146
>

Style nit: why the extra check for block_names being None to later set it to
an empty tuple? Why not make the default argument the empty tuple?

>
> Leaving issue open for the moment - the 3.1 test_warnings fails if I
> don't get a fresh copy of _warnings before running the unit tests. I
> want to figure out why that is necessary before closing the issue.

Might have to do with _warnings trying to import warnings for certain things
in certain cases.

And just something I thought about, Nick, is possibly coming up with a class
decorator that sets self.module on the class. This could have the perk of
taking an optional argument that checks if the optimized module is even in
existence so as to skip running the tests twice if it is not needed. Then
again this might over-optimizing and best to just let the tests run twice
even if it is not needed.
msg85880 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2009-04-12 00:35
The None->tuple check is a legacy of the original API where "None"
actually meant to block "_name". I'll change it as you suggest.

Your explanation as to why the test was failing in py3k makes sense. I
think I will tidy that use case up a bit by adding a "fresh=()" argument
to the function to go along with the "blocked=()" argument. Then the two
warnings imports would be:
  py_warnings = support.import_fresh_module('warnings',
blocked=['_warnings']
  c_warnings = support.import_fresh_module('warnings', fresh=['_warnings']

On the last topic, implementations that don't have an accelerated
version of a module can use the new features for marking implementation
specific tests to skip over those ones.
msg86305 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2009-04-22 16:14
New and improved version added to 2.7 as r71799 and 3.1 as r71801.

Also cleaned up a few leftover references to test.test_support in the
test package documentation.
History
Date User Action Args
2009-04-22 16:14:51ncoghlansetstatus: open -> closed
resolution: accepted
messages: + msg86305
2009-04-12 00:35:36ncoghlansetmessages: + msg85880
2009-04-11 19:36:31brett.cannonsetfiles: + unnamed

messages: + msg85872
2009-04-11 14:31:11ncoghlansetmessages: + msg85863
2009-04-11 14:29:01ncoghlansetmessages: - msg85862
2009-04-11 14:28:48ncoghlansetmessages: + msg85862
2009-04-11 14:25:17ncoghlansetmessages: + msg85861
2009-02-23 22:13:17brett.cannonsetfiles: + unnamed
messages: + msg82647
2009-02-23 21:19:31ncoghlancreate