Skip to content

Commit 6d2e5d7

Browse files
author
Вадим Козыревский
committed
Setting project coverage
1 parent 935ec01 commit 6d2e5d7

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

.github/workflows/tests.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,46 @@ jobs:
6363
python -m pip install --upgrade pip
6464
pip install -e ".[dev]"
6565
66-
- name: Run tests
66+
- name: Start infrastructure
6767
run: |
68-
pytest --cov=src --cov-report=xml ./tests/unit
68+
docker compose -f docker-compose-test.yml up -d
69+
70+
- name: Wait for MySQL
71+
run: |
72+
for i in $(seq 1 30); do
73+
if docker compose -f docker-compose-test.yml exec -T mysql_tests mysqladmin ping -h localhost -ucqrs -pcqrs --silent 2>/dev/null; then
74+
echo "MySQL is ready"
75+
exit 0
76+
fi
77+
echo "Waiting for MySQL... ($i/30)"
78+
sleep 2
79+
done
80+
echo "MySQL did not become ready in time"
81+
exit 1
82+
83+
- name: Wait for Redis
84+
run: |
85+
for i in $(seq 1 15); do
86+
if docker compose -f docker-compose-test.yml exec -T redis_tests redis-cli ping 2>/dev/null | grep -q PONG; then
87+
echo "Redis is ready"
88+
exit 0
89+
fi
90+
echo "Waiting for Redis... ($i/15)"
91+
sleep 1
92+
done
93+
echo "Redis did not become ready in time"
94+
exit 1
95+
96+
- name: Run all tests with coverage
97+
run: |
98+
pytest -c ./tests/pytest-config.ini --cov=src --cov-report=xml --cov-report=term -o cache_dir=/tmp/pytest_cache ./tests
6999
70100
- name: Upload coverage to Codecov
71101
uses: codecov/codecov-action@v4
72102
with:
73103
token: ${{ secrets.CODECOV_TOKEN }}
74104
fail_ci_if_error: false
105+
106+
- name: Stop infrastructure
107+
if: always()
108+
run: docker compose -f docker-compose-test.yml down -v

docker-compose-test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: '3'
2+
services:
3+
mysql_tests:
4+
image: mysql:8.3.0
5+
hostname: mysql-dev
6+
restart: always
7+
environment:
8+
MYSQL_PORT: 3306
9+
MYSQL_ROOT_PASSWORD: root
10+
MYSQL_DATABASE: cqrs
11+
MYSQL_USER: cqrs
12+
MYSQL_PASSWORD: cqrs
13+
ports:
14+
- 3307:3306
15+
command: --init-file /data/application/init.sql
16+
volumes:
17+
- ./tests/init_database.sql:/data/application/init.sql
18+
redis_tests:
19+
image: redis:7.2
20+
hostname: redis
21+
ports:
22+
- "6379:6379"

0 commit comments

Comments
 (0)