question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

azure-cli-core: Test failures with conflicting subparsers in Python 3.11.0b3

See original GitHub issue

Related command Attempting to run tests for azure-cli-core.

Describe the bug While running pytest to test azure-cli-core, many tests fail in Python 3.11.0b3 due to conflicting subparsers. Here is an example:

__________________ TestParser.test_parser_error_spellchecker ___________________
[gw0] linux -- Python 3.11.0 /usr/bin/python3

self = <azure.cli.core.tests.test_parser.TestParser testMethod=test_parser_error_spellchecker>

    @mock.patch('importlib.import_module', _mock_import_lib)
    @mock.patch('pkgutil.iter_modules', _mock_iter_modules)
    @mock.patch('azure.cli.core.commands._load_command_loader', _mock_load_command_loader)
    @mock.patch('azure.cli.core.extension.get_extension_modname', _mock_extension_modname)
    @mock.patch('azure.cli.core.extension.get_extensions', _mock_get_extensions)
    def test_parser_error_spellchecker(self):
        cli = DummyCli()
        main_loader = MainCommandsLoader(cli)
        cli.loader = main_loader
    
        cli.loader.load_command_table(None)
    
        parser = cli.parser_cls(cli)
>       parser.load_command_table(cli.loader)

src/azure-cli-core/azure/cli/core/tests/test_parser.py:206: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/azure-cli-core/azure/cli/core/parser.py:100: in load_command_table
    command_parser = subparser.add_parser(command_verb,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = _SubParsersAction(option_strings=[], dest='_subcommand', nargs='A...', const=None, default=None, type=None, choices={'module': 'module'}, required=True, help=None, metavar=None)
name = 'module'
kwargs = {'_command_source': 'azure.cli.core.tests.test_parser', 'cli_help': None, 'conflict_handler': 'error', 'description': None, ...}
aliases = ()

    def add_parser(self, name, **kwargs):
        # set prog from the existing prefix
        if kwargs.get('prog') is None:
            kwargs['prog'] = '%s %s' % (self._prog_prefix, name)
    
        aliases = kwargs.pop('aliases', ())
    
        if name in self._name_parser_map:
>           raise ArgumentError(self, _('conflicting subparser: %s') % name)
E           argparse.ArgumentError: argument _subcommand: conflicting subparser: module

/usr/lib64/python3.11/argparse.py:1185: ArgumentError

For the full output, check the build log from a Fedora package build. I’ve also copied out just the pytest output into a GitHub Gist to make it easier to read.

To Reproduce Run pytest src/azure-cli-core with Python 3.11.0b3.

Expected behavior I expected the tests to pass (as they do in Python 3.10.5).

Environment summary Building an RPM package for azure-cli with Python 3.11.0b3 in Fedora 37.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mdboomcommented, Oct 5, 2022

(Greetings – on the team working on Python 3.11 👋)

This seems to do the trick for me. The workaround for that bug no longer seems to be required.

diff --git a/src/azure-cli-core/azure/cli/core/parser.py b/src/azure-cli-core/azure/cli/core/parser.py
index fbf0a1ab0..dce310304 100644
--- a/src/azure-cli-core/azure/cli/core/parser.py
+++ b/src/azure-cli-core/azure/cli/core/parser.py
@@ -4,6 +4,7 @@
 # --------------------------------------------------------------------------------------------

 import difflib
+import sys

 import argparse
 import argcomplete
@@ -92,7 +93,8 @@ class AzCliCommandParser(CLICommandParser):
             command_verb = command_name.split()[-1]
             # To work around http://bugs.python.org/issue9253, we artificially add any new
             # parsers we add to the "choices" section of the subparser.
-            subparser.choices[command_verb] = command_verb
+            if sys.version_info < (3, 11):
+                subparser.choices[command_verb] = command_verb

             # inject command_module designer's help formatter -- default is HelpFormatter
             fc = metadata.formatter_class or argparse.HelpFormatter

EDIT: lmk if you’d like a PR.

1reaction
jacoboruscommented, Oct 25, 2022

Azure CLI currently doesn’t support Python 3.11.0b3 yet. We will revisit this topic once Python 3.11 is GA.

Python 3.11 is out, can you please merge https://github.com/Azure/azure-cli/pull/24109?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Release Python 3.11.0b3
Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their...
Read more >
Python Release Python 3.11.0b1
Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their...
Read more >
Python Release Python 3.11.1
Python 3.11.1 is the newest major release of the Python programming language, and it contains many new features and optimizations.
Read more >
Python Release Python 3.11.0b5
Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their...
Read more >
Python Release Python 3.11.0b4
Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found