braintree / braintree_python

Braintree Python library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
241 stars 155 forks source link

Unittest failures on Python 3.12 #153

Closed mgorny closed 8 months ago

mgorny commented 8 months ago

General information

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.

hollabaq86 commented 8 months ago

👋 thanks for reaching out and the PR! We'll take a look at this and any other places where we're incompatible with python 12. For internal tracking, issue 26930