From 5f93a4705134de42dba9f3b9d21f6ca0310c64b1 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Fri, 21 Jun 2019 21:40:54 +0800 Subject: [PATCH] Allow to run specific test inside container For example, contrib/run-unittests.sh /src/tests/test_utils ... Please note that the path starts from /src, which is the root directory of code inside container. Signed-off-by: Chenxiong Qi --- contrib/run-unittests.sh | 8 +++++--- docker/Dockerfile-tests | 2 +- docker/Dockerfile-tests-py3 | 2 +- docker/test.sh | 2 +- docs/CONTRIBUTING.rst | 9 +++++++++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/contrib/run-unittests.sh b/contrib/run-unittests.sh index 8f7f01f6..10fa48d2 100755 --- a/contrib/run-unittests.sh +++ b/contrib/run-unittests.sh @@ -19,12 +19,14 @@ enable_py3= with_pgsql= no_tty= -for arg in "$@"; do - case $arg in +while (( "$#" )); do + case "$1" in --py3) enable_py3=1 ;; --with-pgsql) with_pgsql=1 ;; --no-tty) no_tty=1 ;; + *) break ;; esac + shift done image_ns=quay.io/factory2 @@ -64,7 +66,7 @@ if [ -n "$with_pgsql" ]; then ) fi -(cd "$source_dir" && docker run "${container_opts[@]}" $test_image) +(cd "$source_dir" && docker run "${container_opts[@]}" $test_image "$@") rv=$? diff --git a/docker/Dockerfile-tests b/docker/Dockerfile-tests index a25a21e8..66915e3a 100644 --- a/docker/Dockerfile-tests +++ b/docker/Dockerfile-tests @@ -51,4 +51,4 @@ RUN yum -y install \ RUN pip install --upgrade flask-sqlalchemy pytest flake8 tox pip "more-itertools<6.0.0" VOLUME /src WORKDIR /src -CMD ["bash", "docker/test.sh"] +ENTRYPOINT ["docker/test.sh"] diff --git a/docker/Dockerfile-tests-py3 b/docker/Dockerfile-tests-py3 index efc2c1e9..105a48ca 100644 --- a/docker/Dockerfile-tests-py3 +++ b/docker/Dockerfile-tests-py3 @@ -39,4 +39,4 @@ RUN dnf -y install \ && dnf clean all VOLUME /src WORKDIR /src -CMD ["bash", "docker/test-py3.sh"] +ENTRYPOINT ["docker/test-py3.sh"] diff --git a/docker/test.sh b/docker/test.sh index 377a0ee8..349416c2 100755 --- a/docker/test.sh +++ b/docker/test.sh @@ -13,7 +13,7 @@ done rm -f /usr/lib/python2.7/site-packages/virtualenv_support/pip-9* # Since tox seems to ignore `usedevelop` when we have `sitepackages` on, we have to run it manually python setup.py develop --no-deps -/usr/bin/tox -e flake8,py27 +/usr/bin/tox -e flake8,py27 "$@" rv=$? # After running tox, we can revert back to the original requirements.txt file rm -f requirements.txt diff --git a/docs/CONTRIBUTING.rst b/docs/CONTRIBUTING.rst index e2e7d8a8..3714da8b 100644 --- a/docs/CONTRIBUTING.rst +++ b/docs/CONTRIBUTING.rst @@ -29,6 +29,15 @@ There are options to change the tests enviornment: For example, ``contrib/run-unittests.sh --py3 --with-pgsql``. +You can specify the subset of tests to run inside the container as well. Tests +specified from command-line are passed to ``py.test`` directly. Please note that, +the path of each test must start with ``/src/``. For example:: + + contrib/run-unittests.sh \ + /src/tests/test_utils/ \ + /src/tests/test_mmd_resolver.py \ + /src/tests/test_builder/test_koji.py::TestKojiBuilder::test_tag_to_repo + Style Guide ===========