Skip to content

Commit 825446b

Browse files
rmaxR Max Espinoza
and
R Max Espinoza
authored
Fix test requirements and simplified tox config (#295)
fix test requirements and simplified tox config Co-authored-by: R Max Espinoza <me@rmax.dev>
1 parent 48a7a89 commit 825446b

11 files changed

+96
-51
lines changed

.dockerignore

+4-1
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

+1-1
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

+1-1
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

+15-7
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

+16
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.3
1+
0.7.3

docker-compose.yaml

+20
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

+2-2
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

+1-1
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

+11-1
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,

tox.ini

+24-36
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
[tox]
2-
envlist = security,flake8,py{38,39,310,311}-scrapy{26,27,28,29}-redis{42,43,44,45}
3-
minversion = 1.7.0
2+
envlist =
3+
security
4+
flake8
5+
py{38,39,310,311}-scrapy{26,27,28,29}-redis{42,43,44,45,46,50}
6+
minversion = 3.0.0
47

58
[base]
69
deps =
7-
scrapy>=2.6
8-
redis>=4.2
9-
six>=1.5.2
10+
-r requirements-tests.txt
11+
-r requirements.txt
1012

1113
[testenv]
1214
basepython =
@@ -16,26 +18,26 @@ basepython =
1618
py311: python3.11
1719
deps =
1820
{[base]deps}
19-
mock
20-
pytest
21-
pytest-cov
21+
scrapy26: scrapy~=2.6.0
22+
scrapy27: scrapy~=2.7.0
23+
scrapy28: scrapy~=2.8.0
24+
scrapy29: scrapy~=2.9.0
25+
scrapy210: scrapy~=2.10.0
26+
scrapy211: scrapy~=2.11.0
27+
redis42: redis~=4.2.0
28+
redis43: redis~=4.3.0
29+
redis44: redis~=4.4.0
30+
redis45: redis~=4.5.0
31+
redis46: redis~=4.6.0
32+
redis50: redis~=5.0.0
2233
commands =
23-
scrapy26: pip install scrapy==2.6.3
24-
scrapy27: pip install scrapy==2.7.1
25-
scrapy28: pip install scrapy==2.8.0
26-
scrapy29: pip install scrapy==2.9.0
27-
redis42: pip install redis==4.2.0
28-
redis43: pip install redis==4.3.6
29-
redis44: pip install redis==4.4.4
30-
redis45: pip install redis==4.5.5
31-
pip install .
3234
python -m pytest # --cov-report term --cov=scrapy_redis
3335

3436
[testenv:flake8]
35-
basepython = python3.11
37+
basepython =
38+
python3.11
3639
deps =
3740
{[base]deps}
38-
flake8 # https://github.com/tholo/pytest-flake8/issues/81
3941
commands =
4042
flake8 --ignore=W503,E265,E731 docs/ tests/
4143

@@ -46,31 +48,17 @@ deps =
4648
commands =
4749
bandit -r -c .bandit.yml src/ tests/
4850

49-
[testenv:pylint]
50-
basepython = python3.11
51-
deps =
52-
{[base]deps}
53-
pylint==2.12.2
54-
commands =
55-
pylint setup.py docs/ src/ tests/
56-
5751
[testenv:pytest]
5852
basepython = python3.11
5953
deps =
6054
{[testenv]deps}
61-
scrapy==2.6.1
62-
redis==4.2.2
63-
allowlist_externals = sudo
6455
commands =
65-
sudo apt-get update
66-
sudo apt-get install -y redis
67-
sudo systemctl start redis-server
68-
pip install .
6956
python -m pytest --cov-report term --cov=scrapy_redis
7057

7158
[testenv:build]
7259
basepython=python3.11
7360
deps =
7461
{[base]deps}
75-
commands =
76-
pip install .
62+
build
63+
commands =
64+
python -m build

0 commit comments

Comments
 (0)