Add a Dockerfile for running unit tests on CentOS

This commit is contained in:
mprahl
2018-03-23 10:57:31 -04:00
parent caadb13f0e
commit 20d68628d2
3 changed files with 58 additions and 40 deletions

53
Dockerfile-tests Normal file
View File

@@ -0,0 +1,53 @@
FROM centos:7
WORKDIR /build
RUN yum -y update
RUN yum -y install epel-release
RUN yum -y install \
--setopt=deltarpm=0 \
--setopt=install_weak_deps=false \
--setopt=tsflags=nodocs \
createrepo_c \
fedmsg \
fedmsg-hub \
git \
kobo \
kobo-rpmlib \
https://kojipkgs.fedoraproject.org//packages/libmodulemd/1.1.3/1.fc27/x86_64/libmodulemd-1.1.3-1.fc27.x86_64.rpm \
pdc-client \
https://kojipkgs.fedoraproject.org/repos-dist/epel7Server-infra-stg/latest/x86_64/l/libsolv-0.6.33-1.el7.x86_64.rpm \
python-backports-ssl_match_hostname \
python-dogpile-cache \
python-enum34 \
python-fedora \
python-flask \
python-flask-migrate \
python-flask-sqlalchemy \
python-funcsigs \
python-futures \
python-koji \
python-ldap3 \
python-mock \
python-pip \
python-six \
https://kojipkgs.fedoraproject.org/repos-dist/epel7Server-infra-stg/latest/x86_64/p/python2-solv-0.6.33-1.el7.x86_64.rpm \
python-sqlalchemy \
python-tabulate \
# Test-only dependencies
python-flake8 \
python-mock \
python-tox \
rpm-build \
&& yum clean all
# We currently require a newer versions of these Python packages for the tests
RUN pip install --upgrade flask-sqlalchemy pytest flake8
# TODO: Consider making this a volume instead
COPY . .
# We install the python-koji RPM but it doesn't register as installed through pip.
# This hacks keeps tox from install koji from PyPi.
RUN sed -i '/koji/d' requirements.txt
# Delete any leftover compiled Python files
RUN find . -type f \( -name '*.pyc' -or -name '*.pyc' -or -name '__pycache__' \) -exec rm -rf {} \;
# Since tox seems to ignore `usedevelop` when we have `sitepackages` on, we have to run it manually
RUN python setup.py develop
CMD ["/usr/bin/tox", "-e", "flake8,py27"]

View File

@@ -1,48 +1,13 @@
Running Tests
=============
The proper way how to run unit tests is using `tox
<http://tox.readthedocs.io/>`_. See `tox.ini` configuration file in the
topmost directory of the project's repository.
Since MBS requires Python dependencies that aren't available using PyPi (e.g. libsolv bindings),
there is a Docker image that can be used to run the code analysis and unit tests.
For most cases, you need to work against tox's `py27` environment. This
will just invoke the `pytest` command. For the full set of tests, omit the `-e
py27` argument. This will invoke code analysis, security analysis, and
code coverage checks. This will also run any additional environments
that will be added to the `tox.ini` file in the future.
To run the tests::
$ sudo docker build -t mbs/test -f Dockerfile-tests . && sudo docker run mbs/test
Examples
--------
Purge environment (this will remove all untracked files/dirs and
uncommited changes!) and run tests::
$ git clean -fdxe '/.vagrant'
$ tox -e py27
Just recreate tox's `py27` environment and run the tests::
$ tox -e py27 -r
Just rerun tests in the existing `py27` enviromnent::
$ tox -e py27
Pass additional arg(s) to `pytest`, e.g. `-x` to exit on first
error/failed test::
$ tox -e py27 -- -x
Run only tests in the given file or directory::
$ tox -e py27 -- path/to/test_file.py/or/test_dir
For more `tox` or `pytest` options, see the corresponding help/man pages.
*Note: Consider using detox which makes efficient use of multiple CPUs
by running all possible activities in parallel. It has the same options
and configuration that tox has.*
Development
===========

View File

@@ -30,7 +30,7 @@ commands =
basepython = python2
skip_install = true
deps = flake8
commands = flake8 --ignore E731 --exclude .tox,.git,module_build_service/migrations,build
commands = flake8 --ignore E731 --exclude ./.tox,./.git,./module_build_service/migrations,./build
[testenv:bandit]
basepython = python2