kislyuk / argcomplete

Python and tab completion, better together.
https://kislyuk.github.io/argcomplete/
Apache License 2.0
1.39k stars 129 forks source link

test_console_script_module_wheel and test_console_script_package_wheel fail on Python 3.7 with importlib_metadata >= 5 #420

Closed kislyuk closed 1 year ago

kislyuk commented 1 year ago

Unclear if this is an actual issue or a test case artifact.

======================================================================
FAIL: test_console_script_module_wheel (__main__.TestBashGlobal)
Test completing a console_script for a module from a wheel.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./test/test.py", line 1326, in test_console_script_module_wheel
    self._test_console_script(wheel=True)
  File "./test/test.py", line 1311, in _test_console_script
    self.assertEqual(self.sh.run_command(command), "arg\r\n")
AssertionError: "usage: test-module [-h] {arg}\r\ntest-mo[66 chars]\r\n" != 'arg\r\n'
+ arg
- usage: test-module [-h] {arg}
- test-module: error: argument arg: invalid choice: 'a' (choose from 'arg')
======================================================================
FAIL: test_console_script_package_wheel (__main__.TestBashGlobal)
Test completing a console_script for a package from a wheel.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./test/test.py", line 1331, in test_console_script_package_wheel
    self._test_console_script(package=True, wheel=True)
  File "./test/test.py", line 1311, in _test_console_script
    self.assertEqual(self.sh.run_command(command), "arg\r\n")
AssertionError: "usage: test-package [-h] {arg}\r\ntest-p[68 chars]\r\n" != 'arg\r\n'
+ arg
- usage: test-package [-h] {arg}
- test-package: error: argument arg: invalid choice: 'a' (choose from 'arg')

----------------------------------------------------------------------
flu0r1ne commented 1 year ago

I've recently noticed an issue and it's highly likely that it's related to #436.

hroncok commented 1 year ago

I get the same failures in Fedora with Python 3.12.0b2 even with(out) https://github.com/kislyuk/argcomplete/pull/436:

=================================== FAILURES ===================================
__________________ TestBashGlobal.test_console_script_module ___________________

self = <test.test.TestBashGlobal testMethod=test_console_script_module>

    @unittest.skipIf(os.uname()[0] == "Darwin", "Skip test that fails on MacOS")
    def test_console_script_module(self):
        """Test completing a console_script for a module."""
>       self._test_console_script()

test/test.py:1293: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test/test.py:1288: in _test_console_script
    self.assertEqual(self.sh.run_command(command), 'arg\r\n')
E   AssertionError: "usage: test-module [-h] {arg}\r\ntest-mo[66 chars]\r\n" != 'arg\r\n'
E   + arg
E   - usage: test-module [-h] {arg}
E   - test-module: error: argument arg: invalid choice: 'a' (choose from 'arg')
_______________ TestBashGlobal.test_console_script_module_wheel ________________

self = <test.test.TestBashGlobal testMethod=test_console_script_module_wheel>

    @unittest.skipIf(os.uname()[0] == "Darwin", "Skip test that fails on MacOS")
    def test_console_script_module_wheel(self):
        """Test completing a console_script for a module from a wheel."""
>       self._test_console_script(wheel=True)

test/test.py:1303: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test/test.py:1288: in _test_console_script
    self.assertEqual(self.sh.run_command(command), 'arg\r\n')
E   AssertionError: "usage: test-module [-h] {arg}\r\ntest-mo[66 chars]\r\n" != 'arg\r\n'
E   + arg
E   - usage: test-module [-h] {arg}
E   - test-module: error: argument arg: invalid choice: 'a' (choose from 'arg')
__________________ TestBashGlobal.test_console_script_package __________________

self = <test.test.TestBashGlobal testMethod=test_console_script_package>

    @unittest.skipIf(os.uname()[0] == "Darwin", "Skip test that fails on MacOS")
    def test_console_script_package(self):
        """Test completing a console_script for a package."""
>       self._test_console_script(package=True)

test/test.py:1298: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test/test.py:1288: in _test_console_script
    self.assertEqual(self.sh.run_command(command), 'arg\r\n')
E   AssertionError: "usage: test-package [-h] {arg}\r\ntest-p[68 chars]\r\n" != 'arg\r\n'
E   + arg
E   - usage: test-package [-h] {arg}
E   - test-package: error: argument arg: invalid choice: 'a' (choose from 'arg')
_______________ TestBashGlobal.test_console_script_package_wheel _______________

self = <test.test.TestBashGlobal testMethod=test_console_script_package_wheel>

    @unittest.skipIf(os.uname()[0] == "Darwin", "Skip test that fails on MacOS")
    def test_console_script_package_wheel(self):
        """Test completing a console_script for a package from a wheel."""
>       self._test_console_script(package=True, wheel=True)

test/test.py:1308: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test/test.py:1288: in _test_console_script
    self.assertEqual(self.sh.run_command(command), 'arg\r\n')
E   AssertionError: "usage: test-package [-h] {arg}\r\ntest-p[68 chars]\r\n" != 'arg\r\n'
E   + arg
E   - usage: test-package [-h] {arg}
E   - test-package: error: argument arg: invalid choice: 'a' (choose from 'arg')
kislyuk commented 1 year ago

@hroncok that looks like pytest output. Is that right?

kislyuk commented 1 year ago

OK, I'm fairly certain the output you pasted above is from Pytest @hroncok .

Please respect the maintainers' time and refrain from posting bug reports in this project based on test failures in pytest. This package's default configuration provides for running tests using unittest, and only test failures in unittest should be considered. While pytest's unittest emulation is pretty good, it's not perfect and it's not good enough for running tests in this package.

I'm going to close this issue now since the tests in question pass on Python 3.7 after @flu0r1ne's fix (thanks!)

hroncok commented 1 year ago

Yes it is pytest, but no, it's not happening just with pytest. I merely used pytest to have a nicer control of running only the tests I wanted to show. Same failures happen without pytest.

kislyuk commented 1 year ago

OK, sounds like this might be a Python 3.12 issue. It's probably not related to the issue with the backport that we fixed. Please open a separate issue.

hroncok commented 1 year ago

Please open a separate issue.

Will do.

hroncok commented 1 year ago

https://github.com/kislyuk/argcomplete/issues/440