Skip to content

Unittest failures on Python 3.12 #153

@mgorny

Description

@mgorny

General information

  • SDK/Library version: 4.23.0
  • Environment: n/a
  • Language, language version, and OS: Python 3.12.0 on Gentoo amd64

Issue description

When running the test suite on Python 3.12, I'm getting the following failures:

$ python -m unittest discover tests/unit
..............................E.E.........................................................................................................................................................................................................................................................................................................................................................
======================================================================
ERROR: test_credit_card_options_require_customer_id (test_client_token.TestClientToken.test_credit_card_options_require_customer_id)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/braintree_python/tests/unit/test_client_token.py", line 6, in test_credit_card_options_require_customer_id
    with self.assertRaisesRegexp(InvalidSignatureError, option):
         ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'TestClientToken' object has no attribute 'assertRaisesRegexp'. Did you mean: 'assertRaisesRegex'?

======================================================================
ERROR: test_configuration (unittest.loader._FailedTest.test_configuration)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_configuration
Traceback (most recent call last):
  File "/usr/lib/python3.12/unittest/loader.py", line 382, in _find_test_path
    module = self._get_module_from_name(name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/unittest/loader.py", line 325, in _get_module_from_name
    __import__(name)
  File "/tmp/braintree_python/tests/unit/test_configuration.py", line 4, in <module>
    import imp
ModuleNotFoundError: No module named 'imp'


----------------------------------------------------------------------
Ran 378 tests in 0.063s

FAILED (errors=2)

The first one is merely a matter of replacing it with assertRaisesRegex() (works since Python 3.2), the second one seems to require replacing imp with importlib (which has a reload() function as well). I can submit a PR if you wish.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions