Conversation
Failing test:
```
def test_unknown_command(capsys):
result = main(argv=['unknown', 'a1', 'a2'], commands=dict(fake=FakeCommand))
assert result == 2
captured = capsys.readouterr()
exp = "invalid choice: 'unknown' (choose from 'fake')"
> assert exp in captured.err
E assert "invalid choice: 'unknown' (choose from 'fake')" in "usage: python3 -m deal [-h] {fake} ...\npython3 -m deal: error: argument {fake}: invalid choice: 'unknown' (choose from fake)\n"
E + where "usage: python3 -m deal [-h] {fake} ...\npython3 -m deal: error: argument {fake}: invalid choice: 'unknown' (choose from fake)\n" = CaptureResult(out='', err="usage: python3 -m deal [-h] {fake} ...\npython3 -m deal: error: argument {fake}: invalid choice: 'unknown' (choose from fake)\n").err
tests/test_cli/test_main.py:27: AssertionError
```
|
Thank you! The tests used to pass. I assume it has changed in the latest Python release. I've triggered run CI to confirm. We might need to allow both versions in tests. UPD: Yep, CI for older Python versions expects the version with quotes. |
|
Huh, it's even more interesting: Python 3.12.3 has the quotes and Python 3.12.9 doesn't. I assume, they lost it by accident, bugfix releases shouldn't change user-facing output without a very good reason. |
|
Thank you :) |
|
You're welcome! I created a PR on cpython as well, which has some comments on this. They also mentioned this is new to 3.12.9, so nice catch! 😄 |
|
I also mentioned there that changing the output of an error is a breaking change because it breaks tests that expect to fail, such as this one. Maybe they'll change it back to the quoted version, so it could be interesting to stay tuned to that discussion. That's because, even though argparse doesn't quote anymore, optparse still does, so it's a bit inconsistent. |
Failing test:
Even though argparse's documentation specifies that it single-quotes the choices, it actually doesn't, according to their own tests.