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

unittest ValueError when invoking as module #90579

Closed
BaderSZ mannequin opened this issue Jan 17, 2022 · 6 comments
Closed

unittest ValueError when invoking as module #90579

BaderSZ mannequin opened this issue Jan 17, 2022 · 6 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@BaderSZ
Copy link
Mannequin

BaderSZ mannequin commented Jan 17, 2022

BPO 46421
Nosy @rbtcollins, @ezio-melotti, @voidspace, @serhiy-storchaka, @JelleZijlstra, @miss-islington, @kumaraditya303, @BaderSZ
PRs
  • bpo-46421: Fix unittest filename evaluation when called as a module #30654
  • [3.10] bpo-46421: Fix unittest filename evaluation when called as a module (GH-30654) #31969
  • [3.9] bpo-46421: Fix unittest filename evaluation when called as a module (GH-30654) #31970
  • 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 = None
    closed_at = <Date 2022-03-18.03:25:14.619>
    created_at = <Date 2022-01-17.23:35:01.985>
    labels = ['type-bug', '3.8', '3.9', '3.10', '3.11', '3.7', 'library']
    title = 'unittest ValueError when invoking as module'
    updated_at = <Date 2022-03-18.03:25:14.618>
    user = 'https://github.com/BaderSZ'

    bugs.python.org fields:

    activity = <Date 2022-03-18.03:25:14.618>
    actor = 'JelleZijlstra'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-18.03:25:14.619>
    closer = 'JelleZijlstra'
    components = ['Library (Lib)']
    creation = <Date 2022-01-17.23:35:01.985>
    creator = 'BaderSZ'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46421
    keywords = ['patch']
    message_count = 5.0
    messages = ['410833', '410834', '415461', '415462', '415468']
    nosy_count = 8.0
    nosy_names = ['rbcollins', 'ezio.melotti', 'michael.foord', 'serhiy.storchaka', 'JelleZijlstra', 'miss-islington', 'kumaraditya', 'BaderSZ']
    pr_nums = ['30654', '31969', '31970']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46421'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

    @BaderSZ
    Copy link
    Mannequin Author

    BaderSZ mannequin commented Jan 17, 2022

    When running a local unittest as a module (for example, python -m unittest ./tests/*.py), the command fails with a ValueError. However, if we remove the local directory definition, and call it as python -m unittest tests/*.py, it runs without issue.

    A GitHub pull request with a pull request will be sent promptly.

    @BaderSZ BaderSZ mannequin added 3.10 only security fixes stdlib Python modules in the Lib dir labels Jan 17, 2022
    @BaderSZ
    Copy link
    Mannequin Author

    BaderSZ mannequin commented Jan 17, 2022

    For reference, this is the error request:

    python3 -m unittest ./tests/*.py
    Traceback (most recent call last):
      File "/usr/lib64/python3.10/runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/usr/lib64/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/usr/lib64/python3.10/unittest/__main__.py", line 18, in <module>
        main(module=None)
      File "/usr/lib64/python3.10/unittest/main.py", line 100, in __init__
        self.parseArgs(argv)
      File "/usr/lib64/python3.10/unittest/main.py", line 147, in parseArgs
        self.createTests()
      File "/usr/lib64/python3.10/unittest/main.py", line 158, in createTests
        self.test = self.testLoader.loadTestsFromNames(self.testNames,
      File "/usr/lib64/python3.10/unittest/loader.py", line 220, in loadTestsFromNames
        suites = [self.loadTestsFromName(name, module) for name in names]
      File "/usr/lib64/python3.10/unittest/loader.py", line 220, in <listcomp>
        suites = [self.loadTestsFromName(name, module) for name in names]
      File "/usr/lib64/python3.10/unittest/loader.py", line 154, in loadTestsFromName
        module = __import__(module_name)
    ValueError: Empty module name
    

    The issue stems with having "." as its own value in the parts list of unittest/loader.py.

    https://github.com/python/cpython/blob/main/Lib/unittest/loader.py#L125

    @kumaraditya303 kumaraditya303 added 3.9 only security fixes 3.11 only security fixes type-bug An unexpected behavior, bug, or error labels Jan 22, 2022
    @BaderSZ BaderSZ mannequin added 3.7 (EOL) end of life 3.8 only security fixes labels Jan 22, 2022
    @JelleZijlstra
    Copy link
    Member

    New changeset a0db11b by Bader Zaidan in branch 'main':
    bpo-46421: Fix unittest filename evaluation when called as a module (GH-30654)
    a0db11b

    @miss-islington
    Copy link
    Contributor

    New changeset 0b5f99a by Miss Islington (bot) in branch '3.10':
    bpo-46421: Fix unittest filename evaluation when called as a module (GH-30654)
    0b5f99a

    @JelleZijlstra
    Copy link
    Member

    New changeset 1cab44d by Miss Islington (bot) in branch '3.9':
    [3.9] bpo-46421: Fix unittest filename evaluation when called as a module (GH-30654) (GH-31970)
    1cab44d

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    thomas-roos added a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 20, 2023
    thomas-roos added a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 20, 2023
    github-actions bot pushed a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 20, 2023
    github-actions bot pushed a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 20, 2023
    github-actions bot pushed a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 20, 2023
    aws-iot-embedded-linux-ci2 pushed a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 20, 2023
    aws-iot-embedded-linux-ci2 pushed a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 20, 2023
    aws-iot-embedded-linux-ci2 pushed a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 20, 2023
    thomas-roos added a commit to thomas-roos/meta-aws that referenced this issue Mar 27, 2023
    thomas-roos added a commit to thomas-roos/meta-aws that referenced this issue Mar 27, 2023
    thomas-roos added a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 27, 2023
    thomas-roos added a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 27, 2023
    github-actions bot pushed a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 27, 2023
    aws-iot-embedded-linux-ci2 pushed a commit to aws4embeddedlinux/meta-aws that referenced this issue Mar 27, 2023
    @AliRn76
    Copy link

    AliRn76 commented Dec 18, 2023

    I'm not sure what is wrong but I still have this issue on windows, tell me if you need any more information
    (The log below is from github workflow windows-latest)

    Run python -m unittest .\tests\test_*.py
    Traceback (most recent call last):
      File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\unittest\__main__.py", line 18, in <module>
        main(module=None)
      File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\unittest\main.py", line 100, in __init__
        self.parseArgs(argv)
      File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\unittest\main.py", line 147, in parseArgs
        self.createTests()
      File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\unittest\main.py", line 158, in createTests
        self.test = self.testLoader.loadTestsFromNames(self.testNames,
      File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\unittest\loader.py", line 220, in loadTestsFromNames
        suites = [self.loadTestsFromName(name, module) for name in names]
      File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\unittest\loader.py", line 220, in <listcomp>
        suites = [self.loadTestsFromName(name, module) for name in names]
      File "C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\unittest\loader.py", line 154, in loadTestsFromName
        module = __import__(module_name)
    ValueError: Empty module name
    

    AliRn76 added a commit to AliRn76/panther that referenced this issue Dec 23, 2023
    AliRn76 added a commit to AliRn76/panther that referenced this issue Dec 23, 2023
    AliRn76 added a commit to AliRn76/panther that referenced this issue Dec 23, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants