Skip to content

Commit

Permalink
Compatibility with python 3.13 (patroni#3246)
Browse files Browse the repository at this point in the history
- fix unit tests (logging now uses time.time_ns() instead of time.time())
- update setup.py
- update tox.ini
- enable unix and behave tests with 3.13

Close patroni#3243
  • Loading branch information
CyberDem0n authored Jan 20, 2025
1 parent 3938bb9 commit 7db7dfd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ jobs:
- name: Run tests and flake8
run: python .github/workflows/run_tests.py

- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: 3.13
if: matrix.os != 'macos'
- name: Install dependencies
run: python .github/workflows/install_deps.py
if: matrix.os != 'macos'
- name: Run tests and flake8
run: python .github/workflows/run_tests.py
if: matrix.os != 'macos'

- name: Combine coverage
run: python .github/workflows/run_tests.py combine

Expand All @@ -102,7 +114,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu]
python-version: [3.7, 3.12]
python-version: [3.7, 3.13]
dcs: [etcd, etcd3, consul, exhibitor, kubernetes, raft]
include:
- os: macos
Expand Down Expand Up @@ -194,10 +206,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.12
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: 3.12
python-version: 3.13
- name: Install dependencies
run: python .github/workflows/install_deps.py
- name: Update ydiff
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: Implementation :: CPython',
]

Expand Down
3 changes: 2 additions & 1 deletion tests/test_consul.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def test_update_leader(self, mock_renew):
self.assertTrue(self.c.update_leader(cluster, 12345, failsafe={'foo': 'bar'}))
with patch.object(KV, 'put', Mock(side_effect=ConsulException)):
self.assertFalse(self.c.update_leader(cluster, 12345))
with patch('time.time', Mock(side_effect=[0, 0, 0, 0, 100, 200, 300])):
mock_time = Mock(side_effect=[0, 0, 0, 0, 100, 200, 300])
with patch('time.time', mock_time), patch('time.time_ns', mock_time):
self.assertRaises(ConsulError, self.c.update_leader, cluster, 12345)
with patch('time.time', Mock(side_effect=[0, 100, 200, 300])):
self.assertRaises(ConsulError, self.c.update_leader, cluster, 12345)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ def test__update_leader_with_retry(self, mock_patch, mock_read):
mock_patch.side_effect = [k8s_client.rest.ApiException(409, ''),
k8s_client.rest.ApiException(409, ''), mock_namespaced_kind()]
mock_read.return_value.metadata.resource_version = '2'
with patch('time.time', Mock(side_effect=[0, 0, 100, 200, 0, 0, 0, 0, 0, 100, 200])):
mock_time = Mock(side_effect=[0, 0, 100, 200, 0, 0, 0, 0, 0, 100, 200])
with patch('time.time', mock_time), patch('time.time_ns', mock_time):
self.assertFalse(self.k.update_leader(cluster, '123'))
self.assertFalse(self.k.update_leader(cluster, '123'))
mock_patch.side_effect = k8s_client.rest.ApiException(409, '')
Expand Down
12 changes: 6 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[common]
python_matrix = {36,37,38,39,310,311}
python_matrix = {36,37,38,39,310,311,312,313}
postgres_matrix =
pg11: PG_MAJOR = 11
pg12: PG_MAJOR = 12
Expand All @@ -8,7 +8,7 @@ postgres_matrix =
pg15: PG_MAJOR = 15
pg16: PG_MAJOR = 16
psycopg_deps =
py{37,38,39,310,311}-{lin,win}: psycopg[binary]
py{37,38,39,310,311,312,313}-{lin,win}: psycopg[binary]
mac: psycopg2-binary
py36: psycopg2-binary
platforms =
Expand Down Expand Up @@ -44,7 +44,7 @@ commands = flake8 {posargs:patroni tests setup.py}
deps =
flake8

[testenv:py{36,37,38,39,310,311}-test-{lin,win,mac}]
[testenv:py{36,37,38,39,310,311,312,313}-test-{lin,win,mac}]
description = Run unit tests with pytest
labels =
test
Expand Down Expand Up @@ -88,7 +88,7 @@ deps =
pipdeptree
{[common]psycopg_deps}

[testenv:py{37,38,39,310,311}-type-{lin,mac,win}]
[testenv:py{37,38,39,310,311,312,313}-type-{lin,mac,win}]
description = Run static type checking with pyright
labels =
type
Expand Down Expand Up @@ -137,7 +137,7 @@ depends =
pg{11,12,13,14,15,16}-docker-build

# There's a bug which affects calling multiple envs on the command line
# This should be a valid command: tox -e 'py{36,37,38,39,310,311}-behave-{env:DCS}-lin'
# This should be a valid command: tox -e 'py{36,37,38,39,310,311,312,313}-behave-{env:DCS}-lin'
# Replaced with workaround, see https://github.com/tox-dev/tox/issues/2850
commands =
docker run \
Expand All @@ -159,7 +159,7 @@ platform =
; win: win32
mac: darwin

[testenv:py{36,38,39,310,311}-behave-{etcd,etcd3}-{lin,win,mac}]
[testenv:py{36,38,39,310,311,312,313}-behave-{etcd,etcd3}-{lin,win,mac}]
description = Run behaviour tests (locally with tox)
deps =
-r requirements.txt
Expand Down

0 comments on commit 7db7dfd

Please sign in to comment.