Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-40275: Use new test.support helper submodules in tests #20824

Merged
merged 3 commits into from
Jun 25, 2020

Conversation

shihai1991
Copy link
Member

@shihai1991 shihai1991 commented Jun 12, 2020

Use test helpers in the following test cases:

  • test_asyncio
  • test_getopt
  • test_tcl
  • test_xmlrpc

https://bugs.python.org/issue40275

@shihai1991 shihai1991 requested review from 1st1 and asvetlov as code owners June 12, 2020 05:05
@shihai1991 shihai1991 changed the title Use test helpers to replace test.support bpo-40275: Use test helpers to replace test.support [part 1] Jun 12, 2020
@shihai1991 shihai1991 changed the title bpo-40275: Use test helpers to replace test.support [part 1] bpo-40275: Use test helpers to replace test.support in testcases [part 1] Jun 12, 2020
@shihai1991
Copy link
Member Author

@vstinner Hi, victor. Pls take a look if you have free time.

@vstinner
Copy link
Member

@serhiy-storchaka: Hi. Would you be available next week to have a look at what has been done recently in test/support/__init__.py in https://bugs.python.org/issue40275 before we start to convert the whole Python test suite to newer support submodules like support.os_helper? The final goal is remove aliases from support to be able to remove imports, and also to make test/support/__init__.py smaller.

@serhiy-storchaka
Copy link
Member

I do not see a value in getting rid of the os module import. It is one of base modules, and it is used in the test launcher and in most tests, so you actually cannot get rid of importing it. It just disturbs the files history and makes the software archeology harder. Please stop.

@shihai1991
Copy link
Member Author

I do not see a value in getting rid of the os module import. It is one of base modules, and it is used in the test launcher and in most tests, so you actually cannot get rid of importing it. It just disturbs the files history and makes the software archeology harder. Please stop.

Thanks for your comment, serhiy. IMHO, it's not try to getting rid of the os module import but to control what exact modules we want import in ut.

@serhiy-storchaka
Copy link
Member

They were always imported from the test.support module. And I do not see reasons to change this. It will just clutter the history and break automatic backporting.

@shihai1991
Copy link
Member Author

They were always imported from the test.support module. And I do not see reasons to change this. It will just clutter the history and break automatic backporting.

some testcases like test_unix_events.py have not use test.support directly, the others need keep import test.support(MAYBE we need to split test.support continuously.

@vstinner
Copy link
Member

vstinner commented Jun 15, 2020

@serhiy-storchaka:

I do not see a value in getting rid of the os module import. It is one of base modules, and it is used in the test launcher and in most tests, so you actually cannot get rid of importing it. It just disturbs the files history and makes the software archeology harder. Please stop.
They were always imported from the test.support module. And I do not see reasons to change this. It will just clutter the history and break automatic backporting.

Hi Serhiy,

The creation of the support.os_helper submodule is not directly related the "test.support has way too many imports" https://bugs.python.org/issue40275 issue, but more about the old bpo-15494 "Move test/support.py into a test.support subpackage", commit fb15aa1:

commit fb15aa1e0873043548df782ace51fe1340ea559a
Author: Nick Coghlan <ncoghlan@gmail.com>
Date:   Sun Jul 28 20:56:19 2013 +1000

    Close #15494: test.support is now a package rather than a module
    
    Initial patch by Indra Talip

Between Python 2.7 and Python 3.10, support became 2x larger:

$ wc -l 2.7/Lib/test/support/*.py
 2177 2.7/Lib/test/support/__init__.py
  170 2.7/Lib/test/support/script_helper.py
 2347 total

$ wc -l master/Lib/test/support/*.py
    41 master/Lib/test/support/bytecode_helper.py
    38 master/Lib/test/support/hashlib_helper.py
   238 master/Lib/test/support/import_helper.py
  1960 master/Lib/test/support/__init__.py
   183 master/Lib/test/support/interpreters.py
    29 master/Lib/test/support/logging_helper.py
   611 master/Lib/test/support/os_helper.py
   262 master/Lib/test/support/script_helper.py
   269 master/Lib/test/support/socket_helper.py
   204 master/Lib/test/support/testresult.py
   209 master/Lib/test/support/threading_helper.py
   180 master/Lib/test/support/warnings_helper.py
  4224 total

But this PR is not only about os_helper. There are also support.import_helper and support.warning_helper.

Removing from .import_helper import from support/init.pyremoves 9 imports fromimport test.support`:

- 'importlib',
- 'importlib._bootstrap',
- 'importlib._bootstrap_external',
- 'importlib.abc',
- 'importlib.machinery',
- 'importlib.util',
- 'typing',
- 'typing.io',
- 'typing.re',

If we remove from .warnings_helper import ... from support/__init__.py and top-level import warnings in unittest, it becomes possible to completely avoid importing warnings on import test.support.

They were always imported from the test.support module. And I do not see reasons to change this. It will just clutter the history and break automatic backporting.

If these changes create too many merge conflicts, we can backport https://bugs.python.org/issue40275 changes to 3.8 and 3.9 branches.

@vstinner
Copy link
Member

@shihai1991: Can you please solve the merge conflict?

@shihai1991
Copy link
Member Author

@shihai1991: Can you please solve the merge conflict?

sure, I rebase it now ;)

@shihai1991 shihai1991 changed the title bpo-40275: Use test helpers to replace test.support in testcases [part 1] bpo-40275: Use new test.support helper submodules in tests Jun 25, 2020
@vstinner vstinner merged commit 06a40d7 into python:master Jun 25, 2020
@shihai1991
Copy link
Member Author

thanks, victor :)

@shihai1991 shihai1991 deleted the bpo_40275_helper_replace_1 branch June 25, 2020 12:18
fasih pushed a commit to fasih/cpython that referenced this pull request Jun 29, 2020
arun-mani-j pushed a commit to arun-mani-j/cpython that referenced this pull request Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants