Add way to run Python tests
Added script to easily run Python tests in fuel-library. Script is located in ./utils/jenkins/python_run_tests.sh and uses tox to create environments and py.test as a test runner. Usage of the script can be learn from running it with '-h' arg: ./python_run_tests.sh -h Tests include running all found Python tests as well 'flake8' with 'hacking' checks in newest version. Requirements for tests could be found in ./utils/jenkins/python-test-requirements.txt tox.ini. is located in ./utils/jenkins/tox.ini Disabled all flake8 checks in all currently failing files. DocImpact Change-Id: I283333c48ac53d7baa0a9bb04558d7317bdcec11
This commit is contained in:
parent
e9e4280667
commit
4f12918d5b
|
@ -9,6 +9,7 @@ iso/build
|
|||
|
||||
# Python
|
||||
*.pyc
|
||||
.tox
|
||||
|
||||
# Doc
|
||||
_build
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# flake8: noqa
|
||||
import re
|
||||
import time
|
||||
import os
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# flake8: noqa
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
from base64 import b64encode
|
||||
from cStringIO import StringIO
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# flake8: noqa
|
||||
|
||||
import json
|
||||
import math
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
# It's only required for platforms on which it is not packaged yet.
|
||||
# It should be removed when available everywhere in a package.
|
||||
#
|
||||
# flake8: noqa
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
|
|
@ -38,7 +38,7 @@ Supports KVM, LXC, QEMU, UML, and XEN.
|
|||
:allow_same_net_traffic: Whether to allow in project network traffic
|
||||
|
||||
"""
|
||||
|
||||
# flake8: noqa
|
||||
import errno
|
||||
import hashlib
|
||||
import functools
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# flake8: noqa
|
||||
import re
|
||||
import time
|
||||
import sys
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
# flake8: noqa
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
# flake8: noqa
|
||||
import time
|
||||
import urllib2
|
||||
import sys
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
# flake8: noqa
|
||||
import urllib2
|
||||
import simplejson as json
|
||||
import sys
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
# flake8: noqa
|
||||
import ConfigParser
|
||||
import sys
|
||||
import logging
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
mock>=1.0.1
|
||||
pytest>=2.6.4
|
|
@ -0,0 +1,145 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
set -eu
|
||||
|
||||
ROOT=$(dirname $(readlink -f $0))
|
||||
WORK_DIR="${ROOT}/../../deployment"
|
||||
UTILS_DIR="${ROOT}"
|
||||
TOX_CONF="${ROOT}/tox.ini"
|
||||
#which Python envs (py26, py26, etc.) use for tests
|
||||
TOX_PYENVS=${TOX_PYENVS:-"py26"}
|
||||
|
||||
certain_tests=()
|
||||
flake8_checks=1
|
||||
only_flake8_checks=0
|
||||
python_tests=1
|
||||
testropts=""
|
||||
|
||||
|
||||
check_tox() {
|
||||
type tox >/dev/null 2>&1 || { echo >&2 "Tox is required to be installed to run tests."; exit 1; }
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [OPTIONS] [-- TESTR OPTIONS]"
|
||||
echo "Run Python tests for fuel-library"
|
||||
echo ""
|
||||
echo " -p, --pep8 Run only flake8 checks."
|
||||
echo " -P, --no-pep8 Do not run flake8 tests"
|
||||
echo " -t, --tests Select tests to run. Could be specified"
|
||||
echo " multiple times to select multiple tests"
|
||||
echo " -h, --help Print this usage message and exit."
|
||||
exit
|
||||
}
|
||||
|
||||
|
||||
process_options() {
|
||||
TEMP=$(getopt \
|
||||
-o hpPt: \
|
||||
--long help,pep8,no-pep8,tests: \
|
||||
-n 'run_tests.sh' -- "$@")
|
||||
|
||||
|
||||
eval set -- "$TEMP"
|
||||
|
||||
while true ; do
|
||||
case "$1" in
|
||||
-p|--pep8) only_flake8_checks=1; shift 1;;
|
||||
-P|--no-pep8) flake8_checks=0; shift 1;;
|
||||
-h|--help) usage; shift 1;;
|
||||
-t|--tests) certain_tests+=("$2"); shift 2;;
|
||||
# All parameters and alien options will be passed to testr
|
||||
--) shift 1; testropts+="$@";
|
||||
break;;
|
||||
*) >&2 echo "Internal error: got \"$1\" argument.";
|
||||
usage; exit 1
|
||||
esac
|
||||
|
||||
done
|
||||
|
||||
# Check that specified test file/dir exists. Fail otherwise.
|
||||
if [[ ${#certain_tests[@]} -ne 0 ]]; then
|
||||
for test in ${certain_tests[@]}; do
|
||||
local file_name=${test%:*}
|
||||
echo $file_name
|
||||
|
||||
if [[ ! -f $file_name ]] && [[ ! -d $file_name ]]; then
|
||||
>&2 echo "Error: Specified tests were not found."
|
||||
#exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
run_cleanup() {
|
||||
echo "Doing a clean up."
|
||||
find . -type f -name "*.pyc" -delete
|
||||
}
|
||||
|
||||
|
||||
# run pep8 checks
|
||||
run_flake8() {
|
||||
echo "Starting flake8 checks..."
|
||||
|
||||
tox -e pep8 -c $TOX_CONF -- $testropts $WORK_DIR
|
||||
}
|
||||
|
||||
|
||||
# run tests
|
||||
run_tests() {
|
||||
echo "Starting Python tests..."
|
||||
local tests=$WORK_DIR
|
||||
|
||||
if [[ ${#certain_tests[@]} -ne 0 ]]; then
|
||||
tests=${certain_tests[@]}
|
||||
fi
|
||||
|
||||
tox -e $TOX_PYENVS -c $TOX_CONF -- -v $testropts $tests
|
||||
}
|
||||
|
||||
|
||||
run() {
|
||||
local errors=""
|
||||
|
||||
run_cleanup
|
||||
|
||||
#if flake8 is not disabled or only flake8
|
||||
if [[ $only_flake8_checks -eq 1 ]]; then
|
||||
flake8_checks=1
|
||||
python_tests=0
|
||||
fi
|
||||
|
||||
if [[ $flake8_checks -eq 1 ]]; then
|
||||
run_flake8 || errors+=" flake8"
|
||||
fi
|
||||
|
||||
if [[ $python_tests -eq 1 ]]; then
|
||||
run_tests || errors+=" Python"
|
||||
fi
|
||||
|
||||
# print failed tests
|
||||
if [[ -n "$errors" ]]; then
|
||||
echo Failed tests: $errors
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_tox
|
||||
process_options $@
|
||||
run
|
|
@ -0,0 +1,29 @@
|
|||
# Tox (http://tox.testrun.org/) is a tool for running tests
|
||||
# in multiple virtualenvs. This configuration file will run the
|
||||
# test suite on all supported python versions. To use it, "pip install tox"
|
||||
# and then run "tox" from this directory.
|
||||
|
||||
[tox]
|
||||
minversion = 1.8
|
||||
envlist = pep8
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
deps = -r{toxinidir}/python-test-requirements.txt
|
||||
commands =
|
||||
py.test {posargs:../../deployment}
|
||||
|
||||
[testenv:venv]
|
||||
commands = {posargs:}
|
||||
|
||||
[testenv:pep8]
|
||||
deps = hacking == 0.10.1
|
||||
usedevelop = False
|
||||
commands =
|
||||
flake8 {posargs:}
|
||||
|
||||
[flake8]
|
||||
exclude = .venv,.git,.tox,dist,doc,docs,*egg
|
||||
show-pep8 = True
|
||||
show-source = True
|
||||
count = True
|
Loading…
Reference in New Issue