Skip to content

Commit e8e85e7

Browse files
committed
ci: migrate to pytest and add Redis cluster testing
- Replace unittest with pytest for unit testing - Add Redis cluster setup and testing in GitHub Actions - Update test dependencies and remove coverage from tests/requirements.txt - Modify test run script to use pytest
1 parent 01d9960 commit e8e85e7

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed

.github/workflows/python-package.yml

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,76 @@ jobs:
4141
4242
unittest:
4343
runs-on: ubuntu-latest
44+
strategy:
45+
matrix:
46+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
47+
48+
services:
49+
redis-standalone:
50+
image: redis:alpine
51+
options: >-
52+
--health-cmd "redis-cli ping | grep PONG"
53+
--health-interval 10s
54+
--health-timeout 5s
55+
--health-retries 5
56+
ports:
57+
- 6379:6379
58+
59+
redis-cluster-0:
60+
image: redis:alpine
61+
options: >-
62+
--entrypoint sh
63+
-c "rm -f /tmp/redis-cluster-nodes.conf && redis-server --appendonly no --save '' --cluster-enabled yes --cluster-config-file /tmp/redis-cluster-nodes.conf"
64+
ports:
65+
- 6380:6379
66+
67+
redis-cluster-1:
68+
image: redis:alpine
69+
options: >-
70+
--entrypoint sh
71+
-c "rm -f /tmp/redis-cluster-nodes.conf && redis-server --appendonly no --save '' --cluster-enabled yes --cluster-config-file /tmp/redis-cluster-nodes.conf"
72+
ports:
73+
- 6381:6379
74+
75+
redis-cluster-2:
76+
image: redis:alpine
77+
options: >-
78+
--entrypoint sh
79+
-c "rm -f /tmp/redis-cluster-nodes.conf && redis-server --appendonly no --save '' --cluster-enabled yes --cluster-config-file /tmp/redis-cluster-nodes.conf"
80+
ports:
81+
- 6382:6379
4482

4583
steps:
4684
- uses: actions/checkout@v4
4785

48-
- name: Compose up for unittest
49-
working-directory: .github
50-
run: docker compose up --abort-on-container-exit
86+
- name: Set up Python ${{ matrix.python-version }}
87+
uses: actions/setup-python@v5
88+
with:
89+
python-version: ${{ matrix.python-version }}
90+
cache: pip
91+
92+
- name: Install dependencies
93+
run: |
94+
python -m pip install --upgrade pip
95+
pip install -e . -r tests/requirements.txt
96+
97+
- name: Wait for Redis Cluster nodes to be ready
98+
run: |
99+
timeout 30 sh -c 'until redis-cli -p 6380 ping && redis-cli -p 6381 ping && redis-cli -p 6382 ping; do sleep 1; done'
100+
101+
- name: Create Redis Cluster
102+
run: |
103+
redis-cli --cluster create localhost:6380 localhost:6381 localhost:6382 --cluster-yes
104+
105+
- name: Wait for Redis Cluster to be ready
106+
run: |
107+
timeout 30 sh -c 'until redis-cli -p 6380 --cluster info; do sleep 1; done'
108+
109+
- name: Run tests
110+
run: |
111+
export REDIS_URL=redis://localhost:6379
112+
export REDIS_CLUSTER_NODES="localhost:6380 localhost:6381 localhost:6382"
113+
pytest -x --cov --cov-report=xml --junitxml=junit.xml
51114
52115
- name: Upload coverage to Codecov
53116
uses: codecov/codecov-action@v5

tests/requirements.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
coverage
2-
31
python-dotenv
42

53
Pygments>=2.9
64
pymongo>=3.9
75
msgpack>=1.0
86
PyYAML>=5.4
97
cloudpickle>=3.0
8+
9+
pytest
1010
pytest-asyncio
11+
pytest-cov
12+
pytest-mock

tests/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ do
1818
trap 'rm -rf $TMPDIR' EXIT
1919
${PYTHON} -m venv $TMPDIR
2020
echo
21-
$TMPDIR/bin/pip install --no-compile -e . -r tests/requirements.txt ruff mypy pytest pytest-asyncio pytest-cov types-redis types-PyYAML types-Pygments
21+
$TMPDIR/bin/pip install --no-compile -e . -r tests/requirements.txt ruff mypy types-redis types-PyYAML types-Pygments
2222
echo
2323
echo "Lint check:"
2424
$TMPDIR/bin/ruff check
@@ -27,7 +27,7 @@ do
2727
$TMPDIR/bin/mypy
2828
echo
2929
echo "Unit test:"
30-
$TMPDIR/bin/pytest --cov --cov-report=xml --junitxml=junit.xml
30+
$TMPDIR/bin/pytest -x --cov --cov-report=xml --junitxml=junit.xml
3131
echo
3232
echo "*****************************************************************"
3333
echo "End of ${PYTHON} unit-test"

0 commit comments

Comments
 (0)