I'm getting the following test failure with Python 3.9.7:
======================================================================
FAIL: test_subparser_invalid_option (user_commands.tests.CommandTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.9/unittest/case.py", line 59, in testPartExecutor
yield
File "/usr/lib/python3.9/unittest/case.py", line 592, in run
self._callTestMethod(testMethod)
File "/usr/lib/python3.9/unittest/case.py", line 550, in _callTestMethod
method()
File "/tmp/portage/dev-python/django-3.2.7/work/Django-3.2.7/tests/user_commands/tests.py", line 339, in test_subparser_invalid_option
management.call_command('subparser', 'test', 12)
File "/usr/lib/python3.9/contextlib.py", line 137, in __exit__
self.gen.throw(typ, value, traceback)
File "/tmp/portage/dev-python/django-3.2.7/work/Django-3.2.7/django/test/testcases.py", line 693, in _assert_raises_or_warns_cm
self.assertIn(expected_message, str(getattr(cm, cm_attr)))
File "/usr/lib/python3.9/unittest/case.py", line 1096, in assertIn
self.fail(self._formatMessage(msg, standardMsg))
File "/usr/lib/python3.9/unittest/case.py", line 668, in fail
raise self.failureException(msg)
AssertionError: "Error: invalid choice: 'test' (choose from 'foo')" not found in "Error: argument {foo}: invalid choice: 'test' (choose from 'foo')"
It seems that the output change has been backported from Python 3.10 to 3.9.7.
Ahh yes, see https://github.com/python/cpython/commit/097801844c99ea3916bebe1cc761257ea7083d34. Thanks for the report.
I don't think it's worth switching msg between Python versions, PR.