You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refactor package creation support code into a common location #59608
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2012-07-20.11:13:12.663>labels= ['tests']
title='Refactor package creation support code into a common location'updated_at=<Date2019-07-29.11:44:38.181>user='https://github.com/cjerdonek'
This issue addresses the "file creation" portion of bpo-15376, which is to refactor the walk_package support code in test_runpy into a common location.
It occurs to me that the filecmp/dircmp tests in Lib/test/test_filecmp.py would also benefit from code like this (i.e. being able to create a nested directory of files in one or two lines). And perhaps elsewhere in the tests.
This is an argument for slightly generalizing the test support API in the uploaded patch from creating modules/packages to creating files/directories. A convenience wrapper for packages could still be included that includes an __init__.py in the calls to the underlying directory code.
Lib/test/test_import.py also contains test code that would benefit from this (see for example bpo-15425). (Though not all files need to be refactored in a single issue.)
I feel like it is already too large (it is over 1750 lines), and I did not want to create a third sibling test support module (there is also test/script_helper.py that overlaps with test.support). Do you think that the community would be open to refactoring test.support into a package for Python 3.3? This was meant to assist in increasing test coverage for Python 3.3 bugs.
I feel like it is already too large (it is over 1750 lines), and I did
not want to create a third sibling test support module (there is also
test/script_helper.py that overlaps with test.support). Do you think
that the community would be open to refactoring test.support into a
package for Python 3.3? This was meant to assist in increasing test
coverage for Python 3.3 bugs.
That's too late for 3.3, IMO. Whether or not test.support is too large
is a matter of taste (we have larger files in the stdlib; what makes
test.support annoying to work with is that it's a hodge-podge of utility
functions with little care for consistency). Unless we can clearly
separate it in thematic areas, making it a package would only make
finding stuff more difficult.
At this point, would you advise me to add even more to the existing hodge podge, or to create a third sibling test support module? My patch adds closely related test support functionality.
Incidentally, this discussion relates to the point I was getting at in the python-dev thread in the past couple days about how restrictions on refactoring test support code for maintenance releases can affect the quality of our test code. I am still struggling with how to approach that.
I don't mind refactoring test support routines in maintenance release. I
said it was too late for 3.3 because the beta period is closing; but it
could be fine for 3.3.1 ;)
As for the way forward, I see three possibilites:
put everying in test.support, as a single module (that includes
folding script_helper into it)
make test.support a package of thematic modules
refactor test.support into a variety of independent modules
(script_helper, import_helper, socket_helper, etc.); a small
test.support providing fundamental features such as TESTFN could remain
My personal preference would be for 1) or 3). But whatever we choose, we
should do it consistently. Having a large test.support + a supportlib
package + some independent helpers is not a good idea.
Thanks for your thoughts. For the purposes of this patch, I will change to putting the new support functionality in test.support. Going forward, if we could do some of the refactoring for 3.3.1, that would be great. :)
I worry that the third option may make things worse because it would become less obvious where all of the different test support functionality is located.
Are you opposed to (2), or is it simply less favorable? The transition to (2) could be a gradual one beginning with two or even one module inside the package.
Discoverability is definitely a problem - part of that is a docs issue, since test.support is currently the only one mentioned in the prose docs.
One advantage to moving to a support subpackage is that we can lose the "helper" suffix from the names, while still allowing thematic divisions.
So, for example, we could have
# support.py -> support/__init__.pyimporttest.support# script_helper.py -> support/scripts.pyimporttest.support.scripts# Other possible additionsimporttest.support.importsimporttest.support.network
Even without updating the prose docs, this would help discoverability a lot by having a much smaller directory listing to scan for useful support code. At the moment the general purpose helper modules are mixed in with the tests
I agree with Antoine that we're probably better off handling this as a refactor post-release at this point, though. I'd hoped to have the time to devote to it beforehand, but there's user facing stuff that's higher priority right now.
Cleans up and expands support API to include creating nested directory structures (for use in the filecmp tests, for example).
Adds unit tests for the full API (similar to test_support.py).
Refactors test_filecmp and test_import to use the support code, in addition to test_runpy and test_cmd_line_script. We can remove some of these refactorings if you think it does not add much at this point.
Puts changes in package_helper.py for now (until bpo-15494 is done). I didn't put them in script_helper.py to avoid creating a circular dependency.
italip commented on Jul 9, 2013
italipmannequin
Mannequin
More actions
updated patch to apply on top of patch from bpo-15494
As noted in bpo-18576 and bpo-18578, I'd like for these relocation patches to include the addition of documentation for the submodule in Doc/library/test.rst
Also, now that test.support is a subpackage, the helper should be a submodule of that (test.support.package_helper) rather than directly in the test directory.
I took a look at this last night, and found the combination of moving stuff around *and* refactoring it at the same time was too hard to review.
So, once the PEP-451 changes for runpy are done, I think it would make more sense to tackle this as at least three patches:
Do the refactoring *within* test_runpy to make the helper API a bit cleaner (this should also use types.SimpleNamespace where appropriate rather than a custom alternative)
Move the helper API out to a documented test.support.package_helper module without altering the test.support API
3+. Refactor other test modules to use the now shared API (there may be some pkg related functionality to move out of script_helper as well).
Activity
cjerdonek commentedon Jul 20, 2012
This issue addresses the "file creation" portion of bpo-15376, which is to refactor the walk_package support code in test_runpy into a common location.
cjerdonek commentedon Jul 20, 2012
Attaching patch.
cjerdonek commentedon Jul 26, 2012
It occurs to me that the filecmp/dircmp tests in Lib/test/test_filecmp.py would also benefit from code like this (i.e. being able to create a nested directory of files in one or two lines). And perhaps elsewhere in the tests.
This is an argument for slightly generalizing the test support API in the uploaded patch from creating modules/packages to creating files/directories. A convenience wrapper for packages could still be included that includes an __init__.py in the calls to the underlying directory code.
cjerdonek commentedon Jul 29, 2012
Lib/test/test_import.py also contains test code that would benefit from this (see for example bpo-15425). (Though not all files need to be refactored in a single issue.)
pitrou commentedon Jul 29, 2012
Please let's not have something called test.supportlib in addition to test.support. If test.support grows too large we can turn it into a package.
cjerdonek commentedon Jul 29, 2012
I feel like it is already too large (it is over 1750 lines), and I did not want to create a third sibling test support module (there is also test/script_helper.py that overlaps with test.support). Do you think that the community would be open to refactoring test.support into a package for Python 3.3? This was meant to assist in increasing test coverage for Python 3.3 bugs.
pitrou commentedon Jul 29, 2012
That's too late for 3.3, IMO. Whether or not test.support is too large
is a matter of taste (we have larger files in the stdlib; what makes
test.support annoying to work with is that it's a hodge-podge of utility
functions with little care for consistency). Unless we can clearly
separate it in thematic areas, making it a package would only make
finding stuff more difficult.
cjerdonek commentedon Jul 29, 2012
At this point, would you advise me to add even more to the existing hodge podge, or to create a third sibling test support module? My patch adds closely related test support functionality.
Incidentally, this discussion relates to the point I was getting at in the python-dev thread in the past couple days about how restrictions on refactoring test support code for maintenance releases can affect the quality of our test code. I am still struggling with how to approach that.
pitrou commentedon Jul 29, 2012
I don't mind refactoring test support routines in maintenance release. I
said it was too late for 3.3 because the beta period is closing; but it
could be fine for 3.3.1 ;)
As for the way forward, I see three possibilites:
folding script_helper into it)
(script_helper, import_helper, socket_helper, etc.); a small
test.support providing fundamental features such as TESTFN could remain
My personal preference would be for 1) or 3). But whatever we choose, we
should do it consistently. Having a large test.support + a supportlib
package + some independent helpers is not a good idea.
cjerdonek commentedon Jul 29, 2012
Thanks for your thoughts. For the purposes of this patch, I will change to putting the new support functionality in test.support. Going forward, if we could do some of the refactoring for 3.3.1, that would be great. :)
I worry that the third option may make things worse because it would become less obvious where all of the different test support functionality is located.
Are you opposed to (2), or is it simply less favorable? The transition to (2) could be a gradual one beginning with two or even one module inside the package.
pitrou commentedon Jul 29, 2012
Less favorable, because it produces longer import strings
("test.support.some_helper" instead of "test.some_helper").
cjerdonek commentedon Jul 29, 2012
This can be addressed by exposing the API in __init__.py though (as does, say, the unittest package), no?
pitrou commentedon Jul 29, 2012
Le dimanche 29 juillet 2012 à 17:00 +0000, Chris Jerdonek a écrit :
Yes, that's right.
ncoghlan commentedon Jul 30, 2012
Discoverability is definitely a problem - part of that is a docs issue, since test.support is currently the only one mentioned in the prose docs.
One advantage to moving to a support subpackage is that we can lose the "helper" suffix from the names, while still allowing thematic divisions.
So, for example, we could have
Even without updating the prose docs, this would help discoverability a lot by having a much smaller directory listing to scan for useful support code. At the moment the general purpose helper modules are mixed in with the tests
I agree with Antoine that we're probably better off handling this as a refactor post-release at this point, though. I'd hoped to have the time to devote to it beforehand, but there's user facing stuff that's higher priority right now.
cjerdonek commentedon Jul 30, 2012
Sounds good. Later today I will create an issue to move test/support.py into a test.support subpackage post-release.
We can continue the discussion of how to organize it there.
cjerdonek commentedon Jul 30, 2012
I created bpo-15494 for this.
cjerdonek commentedon Aug 2, 2012
Attaching an updated patch. Changes include:
italip commentedon Jul 9, 2013
updated patch to apply on top of patch from bpo-15494
ncoghlan commentedon Jul 28, 2013
As noted in bpo-18576 and bpo-18578, I'd like for these relocation patches to include the addition of documentation for the submodule in Doc/library/test.rst
ncoghlan commentedon Jul 28, 2013
Also, now that test.support is a subpackage, the helper should be a submodule of that (test.support.package_helper) rather than directly in the test directory.
ncoghlan commentedon Dec 9, 2013
I took a look at this last night, and found the combination of moving stuff around *and* refactoring it at the same time was too hard to review.
So, once the PEP-451 changes for runpy are done, I think it would make more sense to tackle this as at least three patches:
Do the refactoring *within* test_runpy to make the helper API a bit cleaner (this should also use types.SimpleNamespace where appropriate rather than a custom alternative)
Move the helper API out to a documented test.support.package_helper module without altering the test.support API
3+. Refactor other test modules to use the now shared API (there may be some pkg related functionality to move out of script_helper as well).
vstinner commentedon Jul 29, 2019
This issue is 7 years old and has patches: it is no newcomer friendly, I remove the "easy" keyword.