Skip to content

Commit dd0f212

Browse files
authored
Wraps the CyberSource imports in a warnings filter, so we get less chatter from SyntaxWarning issues (#191)
The CyberSource Python REST client library uses a couple of regexes that aren't in raw strings, and (starting with Python 3.12) doing that raises a SyntaxWarning. (This was deprecated in 3.6 but in between then and 3.12 it raised a DeprecationWarning, which is usually invisible.) Wrapping these in a `catch_warnings` context manager lets us filter out SyntaxWarning, so we can make it quiet. (pytest also sometimes regards these as _errors_, which keeps your tests from passing when using Python 3.12+, so this should fix that too.) It would be better for the upstream to be fixed but we can do this until that happens.
1 parent ab58787 commit dd0f212

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Removed
9+
10+
- A bullet item for the Removed category.
11+
12+
-->
13+
<!--
14+
### Added
15+
16+
- A bullet item for the Added category.
17+
18+
-->
19+
### Changed
20+
21+
- Wrap the imports for CyberSource; they generate `SyntaxWarning`s, so this should quiet them down (and allow them to pass tests)
22+
23+
<!--
24+
### Deprecated
25+
26+
- A bullet item for the Deprecated category.
27+
28+
-->
29+
<!--
30+
### Fixed
31+
32+
- A bullet item for the Fixed category.
33+
34+
-->
35+
<!--
36+
### Security
37+
38+
- A bullet item for the Security category.
39+
40+
-->

src/payment_gateway/mitol/payment_gateway/api.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@
77
import hmac
88
import json
99
import uuid
10+
import warnings
1011
from base64 import b64encode
1112
from dataclasses import dataclass
1213
from decimal import Decimal
1314
from functools import wraps
1415

15-
from CyberSource import (
16-
CreateSearchRequest,
17-
Ptsv2paymentsClientReferenceInformation,
18-
Ptsv2paymentsidcapturesOrderInformationAmountDetails,
19-
Ptsv2paymentsidrefundsOrderInformation,
20-
RefundApi,
21-
RefundPaymentRequest,
22-
SearchTransactionsApi,
23-
TransactionDetailsApi,
24-
)
16+
with warnings.catch_warnings():
17+
warnings.filterwarnings("ignore", category=SyntaxWarning)
18+
from CyberSource import (
19+
CreateSearchRequest,
20+
Ptsv2paymentsClientReferenceInformation,
21+
Ptsv2paymentsidcapturesOrderInformationAmountDetails,
22+
Ptsv2paymentsidrefundsOrderInformation,
23+
RefundApi,
24+
RefundPaymentRequest,
25+
SearchTransactionsApi,
26+
TransactionDetailsApi,
27+
)
2528
from django.conf import settings
2629

2730
from mitol.common.utils.datetime import now_in_utc

0 commit comments

Comments
 (0)