Skip to content

Commit

Permalink
Add support for testing with Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlecat committed Dec 19, 2016
1 parent a345a83 commit 54f9c01
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
3 changes: 2 additions & 1 deletion brainzutils/test/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from brainzutils import cache
import unittest
import datetime
import os


class CacheTestCase(unittest.TestCase):
"""Testing our custom wrapper for memcached."""
host = "localhost"
host = os.environ.get("REDIS_HOST", "localhost")
port = 6379
namespace = "NS_TEST"

Expand Down
4 changes: 2 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytest==2.9.2
pytest-cov==2.2.1
pytest==3.0.5
pytest-cov==2.4.0
23 changes: 23 additions & 0 deletions test/Dockerfile.py2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM metabrainz/python:2.7

ENV DOCKERIZE_VERSION v0.2.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

RUN mkdir /code
WORKDIR /code

# Python dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
git
COPY . /code/
RUN pip install -r requirements.txt
RUN pip install -r requirements_dev.txt

ENV REDIS_HOST "redis"

CMD dockerize -wait tcp://redis:6379 -timeout 10s \
py.test --junitxml=/data/test_report.xml \
--cov-report xml:/data/coverage.xml
23 changes: 23 additions & 0 deletions test/Dockerfile.py3
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM metabrainz/python:3.5

ENV DOCKERIZE_VERSION v0.2.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

RUN mkdir /code
WORKDIR /code

# Python dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
git
COPY . /code/
RUN pip install -r requirements.txt
RUN pip install -r requirements_dev.txt

ENV REDIS_HOST "redis"

CMD dockerize -wait tcp://redis:6379 -timeout 10s \
py.test --junitxml=/data/test_report.xml \
--cov-report xml:/data/coverage.xml
13 changes: 13 additions & 0 deletions test/docker-compose.py2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Docker Compose file for testing with Python 2
version: "2"
services:

test:
build:
context: ..
dockerfile: ./test/Dockerfile.py2
links:
- redis

redis:
image: redis:3.2.1
13 changes: 13 additions & 0 deletions test/docker-compose.py3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Docker Compose file for testing with Python 3
version: "2"
services:

test:
build:
context: ..
dockerfile: ./test/Dockerfile.py3
links:
- redis

redis:
image: redis:3.2.1

0 comments on commit 54f9c01

Please sign in to comment.