Skip to content

Commit 825446b

Browse files
rmaxR Max Espinoza
andauthored
Fix test requirements and simplified tox config (#295)
fix test requirements and simplified tox config Co-authored-by: R Max Espinoza <[email protected]>
1 parent 48a7a89 commit 825446b

File tree

11 files changed

+96
-51
lines changed

11 files changed

+96
-51
lines changed

.dockerignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ nosetests.xml
4040
.pydevproject
4141

4242
# JetBrains PyCharm IDE
43-
/.idea/
43+
/.idea/
44+
45+
.venv
46+
.tags

.github/workflows/builds.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ jobs:
2525
env:
2626
TOXENV: build
2727
run: |
28-
pip install -U tox
28+
pip install -r requirements-tests.txt
2929
tox

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ jobs:
2525
env:
2626
TOXENV: ${{ matrix.env }}
2727
run: |
28-
pip install -U tox
28+
pip install -r requirements-tests.txt
2929
tox

.github/workflows/tests.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@ jobs:
1212
matrix:
1313
python-version: ["3.11.3"]
1414

15+
services:
16+
redis:
17+
image: redis
18+
options: >-
19+
--health-cmd "redis-cli ping"
20+
--health-interval 10s
21+
--health-timeout 5s
22+
--health-retries 5
23+
24+
container: python:${{ matrix.python-version }}
25+
1526
steps:
1627
- uses: actions/checkout@v2
1728

18-
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v2
20-
with:
21-
python-version: ${{ matrix.python-version }}
22-
2329
- name: Run pytest
24-
env:
30+
env:
31+
REDIS_HOST: redis
2532
TOXENV: pytest
33+
TOX_TESTENV_PASSENV: REDIS_HOST
2634
run: |
27-
pip install -U tox
35+
pip install -r requirements-tests.txt
2836
tox

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.11-slim
2+
3+
# Set working directory
4+
WORKDIR /app
5+
6+
# Install tox and dependencies (replace 'your-requirements.txt' with your actual file)
7+
COPY requirements.txt .
8+
COPY requirements-tests.txt .
9+
RUN pip install -r requirements.txt -r requirements-tests.txt
10+
11+
# Copy your project code
12+
COPY . .
13+
14+
# Run Tox tests
15+
CMD ["tox"]
16+

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.3
1+
0.7.3

docker-compose.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3.8'
2+
3+
services:
4+
python:
5+
build: .
6+
command: tox -e security,flake8,pytest
7+
environment:
8+
REDIS_HOST: redis # Use service name for hostname within docker network
9+
REDIS_PORT: 6379
10+
TOX_TESTENV_PASSENV: "REDIS_HOST REDIS_PORT"
11+
volumes:
12+
- ./:/app # Mount your project directory into the container
13+
depends_on:
14+
- redis
15+
16+
redis:
17+
image: redis:6.2-alpine
18+
ports:
19+
- "6379:6379" # Map Redis port to host port
20+

requirements-tests.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This packages are required to run all the tests.
22
flake8
33
mock
4-
pytest
4+
pytest>=6.0,<7
55
pytest-cov
6-
tox
6+
tox>=3.0,<4

tests/test_scrapy_redis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
# allow test settings from environment
18-
REDIS_HOST = os.environ.get('REDIST_HOST', 'localhost')
18+
REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
1919
REDIS_PORT = int(os.environ.get('REDIS_PORT', 6379))
2020

2121

tests/test_spiders.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import contextlib
22
import mock
3+
import os
34
import pytest
45

56
from scrapy import signals
@@ -12,6 +13,10 @@
1213
)
1314

1415

16+
REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
17+
REDIS_PORT = int(os.environ.get('REDIS_PORT', 6379))
18+
19+
1520
@contextlib.contextmanager
1621
def flushall(server):
1722
try:
@@ -29,7 +34,10 @@ class MyCrawlSpider(RedisCrawlSpider):
2934

3035

3136
def get_crawler(**kwargs):
32-
return mock.Mock(settings=Settings(), **kwargs)
37+
return mock.Mock(settings=Settings({
38+
"REDIS_HOST": REDIS_HOST,
39+
"REDIS_PORT": REDIS_PORT,
40+
}), **kwargs)
3341

3442

3543
class TestRedisMixin_setup_redis(object):
@@ -124,6 +132,8 @@ def test_consume_urls_from_redis(start_urls_as_zset, start_urls_as_set, spider_c
124132
redis_key = 'start:urls'
125133
crawler = get_crawler()
126134
crawler.settings.setdict({
135+
'REDIS_HOST': REDIS_HOST,
136+
'REDIS_PORT': REDIS_PORT,
127137
'REDIS_START_URLS_KEY': redis_key,
128138
'REDIS_START_URLS_AS_ZSET': start_urls_as_zset,
129139
'REDIS_START_URLS_AS_SET': start_urls_as_set,

0 commit comments

Comments
 (0)