Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests and add github CI #35

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Python application

on: [push]

jobs:
build:
name: Test on Python ${{ matrix.python-version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest]
fail-fast: false
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install -r requirements-test.txt
- name: Test with pytest
env:
PYTHONPATH: .
run: |
pytest --durations=10 --cov dockerctx tests
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Upload coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
# This will only work if we also send a "done" event after the
# whole job is finished.
# See: https://docs.coveralls.io/parallel-build-webhook
#COVERALLS_PARALLEL: "true"
CI_BRANCH: ${{ steps.extract_branch.outputs.branch }}
if: matrix.os == 'ubuntu-latest'
run: |
coveralls
11 changes: 9 additions & 2 deletions dockerctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ def new_container(
else:
logger.info('Stopping container %s', name)
# TODO: container.stop() does not seem to work here (e.g. for postgres)
container.kill()
try:
container.stop(timeout=1)
except docker.errors.APIError as e:
logger.error('Error stopping container: %s', e)

logger.info('Removing container %s', name)
container.remove()
try:
container.remove(force=True)
except docker.errors.APIError as e:
logger.error('Error removing container: %s', e)


def accepting_connections(host, port, timeout=20):
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import logging


logging.basicConfig(level=logging.DEBUG)
8 changes: 5 additions & 3 deletions tests/test_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ def test_pg():
with new_container(
image_name='postgres:alpine',
ports={'5432/tcp': port},
ready_test=lambda: pg_ready('localhost', port),
ready_test=lambda: pg_ready('127.0.0.1', port, timeout=20000),
# Travis CI fails otherwise :`(
docker_api_version='1.24') as container:
docker_api_version='1.24',
environment={'POSTGRES_PASSWORD': 'password'}
) as container:
logger.debug(container.name)

url = "postgres://postgres@localhost:%d/mydb" % port
url = "postgresql://postgres:password@127.0.0.1:%d/mydb" % port
logger.info('create engine')
if not database_exists(url):
logger.info('create database')
Expand Down
Loading