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

Fix test discovery for test_codecmaps*.py #62458

Closed
zware opened this issue Jun 18, 2013 · 11 comments
Closed

Fix test discovery for test_codecmaps*.py #62458

zware opened this issue Jun 18, 2013 · 11 comments
Assignees
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@zware
Copy link
Member

zware commented Jun 18, 2013

BPO 18258
Nosy @brettcannon, @ezio-melotti, @bitdancer, @zware, @serhiy-storchaka
Files
  • test_codecmaps_discovery.diff: test_codecmaps*.py fix, version 1
  • 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 = 'https://github.com/zware'
    closed_at = <Date 2014-07-02.01:26:12.291>
    created_at = <Date 2013-06-18.21:16:03.520>
    labels = ['type-bug', 'tests']
    title = 'Fix test discovery for test_codecmaps*.py'
    updated_at = <Date 2014-07-02.01:26:12.268>
    user = 'https://github.com/zware'

    bugs.python.org fields:

    activity = <Date 2014-07-02.01:26:12.268>
    actor = 'zach.ware'
    assignee = 'zach.ware'
    closed = True
    closed_date = <Date 2014-07-02.01:26:12.291>
    closer = 'zach.ware'
    components = ['Tests']
    creation = <Date 2013-06-18.21:16:03.520>
    creator = 'zach.ware'
    dependencies = []
    files = ['30644']
    hgrepos = []
    issue_num = 18258
    keywords = ['patch']
    message_count = 11.0
    messages = ['191434', '193229', '193231', '193239', '193240', '193242', '193243', '193311', '222060', '222063', '222065']
    nosy_count = 7.0
    nosy_names = ['brett.cannon', 'ezio.melotti', 'r.david.murray', 'BreamoreBoy', 'python-dev', 'zach.ware', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue18258'
    versions = ['Python 3.4', 'Python 3.5']

    @zware
    Copy link
    Member Author

    zware commented Jun 18, 2013

    The test package is almost to the point where I can run PCbuild\python_d.exe -m unittest discover [Lib/test/](https://github.com/python/cpython/blob/main/Lib/test) "test_*.py" and get a useful result, the only thing that still blows up is multibytecodec_support.py. I had not previously noticed this problem due to the way support.open_urlresource works, requiring the 'urlfetch' resource if and only if the requested file has not already been fetched before and stored in the Lib/test/data dir. multibytecodec_support.TestBase_Mapping blows things up because it uses init instead of setUp to try opening the needed file, which causes ResourceDenied to be raised at class creation time rather than test run time, which unittest can't handle. The attached patch fixes this (at the expense of opening and closing the file once per test method, rather than once per class) as well as converting the test_codecmaps* scripts from test_main to unittest.main.

    @zware zware added type-feature A feature request or enhancement tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error and removed type-feature A feature request or enhancement labels Jun 18, 2013
    @serhiy-storchaka
    Copy link
    Member

    What is a purpose of support.use_resources = ['urlfetch']? I don't see any effect.

    @bitdancer
    Copy link
    Member

    It enables the resource when the tests are run via unittest. (That is, it is equivalent to specifying '-u urlfetch' when running regrtest.)

    @serhiy-storchaka
    Copy link
    Member

    But I don't see any effect.

    $ ./python -m test.regrtest -v test_codecmaps_tw
    == CPython 3.3.2+ (3.3:359002d4370d+, Jul 14 2013, 15:34:54) [GCC 4.6.3]
    ==   Linux-3.8.0-27-generic-i686-with-debian-wheezy-sid little-endian
    ==   /home/serhiy/py/cpython-3.3/build/test_python_6295
    Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1)
    [1/1] test_codecmaps_tw
    test_errorhandle (test.test_codecmaps_tw.TestBIG5Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    test_mapping_file (test.test_codecmaps_tw.TestBIG5Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    test_mapping_supplemental (test.test_codecmaps_tw.TestBIG5Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    test_errorhandle (test.test_codecmaps_tw.TestCP950Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    test_mapping_file (test.test_codecmaps_tw.TestCP950Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    test_mapping_supplemental (test.test_codecmaps_tw.TestCP950Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    
    $ ./python -m unittest discover -v Lib/test/ "test_codecmaps_tw.py"
    test_errorhandle (test_codecmaps_tw.TestBIG5Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    test_mapping_file (test_codecmaps_tw.TestBIG5Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    test_mapping_supplemental (test_codecmaps_tw.TestBIG5Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    test_errorhandle (test_codecmaps_tw.TestCP950Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    test_mapping_file (test_codecmaps_tw.TestCP950Map) ... skipped "Use of the 'urlfetch' resource not enabled"
    test_mapping_supplemental (test_codecmaps_tw.TestCP950Map) ... skipped "Use of the 'urlfetch' resource not enabled"

    @bitdancer
    Copy link
    Member

    I'm sorry, I misspoke. It only works when you run the test file as command:

    ./python Lib/test/test_codecmaps_cn.py

    (which uses unittest.main, thus my error in calling it 'via unittest').

    So, the fact that the tests don't run if discovery is used is still a bug. I'm not sure how we fix it, given the nature of the resource.

    @zware
    Copy link
    Member Author

    zware commented Jul 17, 2013

    R. David Murray wrote:

    So, the fact that the tests don't run if discovery is used is still a
    bug. I'm not sure how we fix it, given the nature of the resource.

    My preferred solution short of adding resource management to unittest is to add a "regrtest_run" flag to test.support, defaulting to False and set to True by regrtest (like verbose, use_resources, etc.). Then we can replace the sys._getframe hack in support.requires with a simple check of support.regrtest_run. If it's False, return. This way, running the test module directly or via discovery will work the same way: all resources enabled.

    @bitdancer
    Copy link
    Member

    +1. You should probably open a new issue for that proposal.

    @zware
    Copy link
    Member Author

    zware commented Jul 18, 2013

    Done, bpo-18492.

    I'll submit and updated patch here when (if :)) that one is applied.

    I'm also looking into adding resource handling to unittest itself and it is going pretty well; I hope to have a patch ready for review for that soon.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 1, 2014

    @zach just a reminder that you've committed bpo-18492 in case you'd forgotten this.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 2, 2014

    New changeset 27feb652d3ad by Zachary Ware in branch '3.4':
    Issue bpo-18258: Fix test discovery for test_codecmaps_*.
    http://hg.python.org/cpython/rev/27feb652d3ad

    New changeset b08921c7d1ec by Zachary Ware in branch 'default':
    Issue bpo-18258: Fix test discovery for test_codecmaps_*.
    http://hg.python.org/cpython/rev/b08921c7d1ec

    @zware
    Copy link
    Member Author

    zware commented Jul 2, 2014

    Not forgotten, just hadn't gotten to on the list yet.

    @zware zware closed this as completed Jul 2, 2014
    @zware zware self-assigned this Jul 2, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants