Migrate tests to ostestr
Following commits migrates running monasca-notification tests from nosetest to ostestr, similar to other openstack projects. Additionally, it enables calculating coverage and py35 tests. Extra: * added debug environment with oslo_debug_helper Change-Id: I555176b7f2ed54c3222312da341d433f429c5c6a
This commit is contained in:
parent
6f75509f9c
commit
5de3ee9f23
|
@ -0,0 +1,7 @@
|
||||||
|
[run]
|
||||||
|
branch = True
|
||||||
|
source = monasca_notification
|
||||||
|
omit = tests/*
|
||||||
|
|
||||||
|
[report]
|
||||||
|
ignore_errors = True
|
|
@ -11,3 +11,7 @@ build
|
||||||
dist
|
dist
|
||||||
monasca_notification.egg-info
|
monasca_notification.egg-info
|
||||||
.*.sw*
|
.*.sw*
|
||||||
|
|
||||||
|
.testrepository/
|
||||||
|
.coverage
|
||||||
|
cover/
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
[DEFAULT]
|
||||||
|
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
|
||||||
|
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
|
||||||
|
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \
|
||||||
|
${PYTHON:-python} -m subunit.run discover -t ./ $OS_TEST_PATH $LISTOPT $IDOPTION
|
||||||
|
|
||||||
|
test_id_option=--load-list $IDFILE
|
||||||
|
test_list_option=--list
|
||||||
|
group_regex=monasca_notification\.tests(?:\.|_)([^_]+)
|
|
@ -13,6 +13,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -23,25 +25,35 @@ from monasca_notification.plugins import webhook_notifier
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
possible_notifiers = []
|
possible_notifiers = None
|
||||||
configured_notifiers = {}
|
configured_notifiers = None
|
||||||
statsd_counter = {}
|
statsd_counter = None
|
||||||
|
|
||||||
statsd = None
|
statsd = None
|
||||||
statsd_timer = None
|
statsd_timer = None
|
||||||
|
|
||||||
|
|
||||||
def init(statsd_obj):
|
def init(statsd_obj):
|
||||||
global statsd, statsd_timer
|
global statsd, statsd_timer, \
|
||||||
|
possible_notifiers, configured_notifiers,\
|
||||||
|
statsd_counter
|
||||||
|
|
||||||
statsd = statsd_obj
|
statsd = statsd_obj
|
||||||
statsd_timer = statsd.get_timer()
|
statsd_timer = statsd.get_timer()
|
||||||
|
|
||||||
possible_notifiers.append(email_notifier.EmailNotifier(log))
|
statsd_counter = {}
|
||||||
possible_notifiers.append(webhook_notifier.WebhookNotifier(log))
|
configured_notifiers = {}
|
||||||
possible_notifiers.append(pagerduty_notifier.PagerdutyNotifier(log))
|
|
||||||
|
possible_notifiers = [
|
||||||
|
email_notifier.EmailNotifier(log),
|
||||||
|
webhook_notifier.WebhookNotifier(log),
|
||||||
|
pagerduty_notifier.PagerdutyNotifier(log)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def load_plugins(config):
|
def load_plugins(config):
|
||||||
|
global possible_notifiers
|
||||||
|
|
||||||
for plugin_class in config.get("plugins", []):
|
for plugin_class in config.get("plugins", []):
|
||||||
try:
|
try:
|
||||||
possible_notifiers.append(simport.load(plugin_class)(log))
|
possible_notifiers.append(simport.load(plugin_class)(log))
|
||||||
|
@ -50,14 +62,18 @@ def load_plugins(config):
|
||||||
|
|
||||||
|
|
||||||
def enabled_notifications():
|
def enabled_notifications():
|
||||||
|
global configured_notifiers
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
for key in configured_notifiers:
|
for key in configured_notifiers:
|
||||||
results.append(key.upper())
|
results.append(key.upper())
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def config(config):
|
def config(cfg):
|
||||||
formatted_config = {type.lower(): value for type, value in config.iteritems()}
|
global possible_notifiers, configured_notifiers, statsd_counter
|
||||||
|
|
||||||
|
formatted_config = {t.lower(): v for t, v in six.iteritems(cfg)}
|
||||||
for notifier in possible_notifiers:
|
for notifier in possible_notifiers:
|
||||||
ntype = notifier.type.lower()
|
ntype = notifier.type.lower()
|
||||||
if ntype in formatted_config:
|
if ntype in formatted_config:
|
||||||
|
@ -102,6 +118,8 @@ def send_notifications(notifications):
|
||||||
|
|
||||||
|
|
||||||
def send_single_notification(notification):
|
def send_single_notification(notification):
|
||||||
|
global configured_notifiers
|
||||||
|
|
||||||
ntype = notification.type
|
ntype = notification.type
|
||||||
try:
|
try:
|
||||||
return configured_notifiers[ntype].send_notification(notification)
|
return configured_notifiers[ntype].send_notification(notification)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
# The order of packages is significant, because pip processes them in the order
|
# The order of packages is significant, because pip processes them in the order
|
||||||
# of appearance. Changing the order has an impact on the overall integration
|
# of appearance. Changing the order has an impact on the overall integration
|
||||||
# process, which may cause wedges in the gate later.
|
# Hacking already pins down pep8, pyflakes and flake8
|
||||||
hacking<0.12,>=0.11.0 # Apache-2.0
|
hacking>=0.12.0,!=0.13.0,<0.14 # Apache-2.0
|
||||||
pyflakes==0.8.1 # MIT
|
coverage>=4.0 # Apache-2.0
|
||||||
nose # LGPL
|
|
||||||
nosexcover # BSD
|
|
||||||
mock>=2.0 # BSD
|
mock>=2.0 # BSD
|
||||||
funcsigs>=0.4;python_version=='2.7' or python_version=='2.6' # Apache-2.0
|
funcsigs>=0.4;python_version=='2.7' or python_version=='2.6' # Apache-2.0
|
||||||
|
os-testr>=0.8.0 # Apache-2.0
|
||||||
|
testrepository>=0.0.18 # Apache-2.0/BSD
|
||||||
SQLAlchemy<1.1.0,>=1.0.10 # MIT
|
SQLAlchemy<1.1.0,>=1.0.10 # MIT
|
||||||
|
|
45
tox.ini
45
tox.ini
|
@ -1,30 +1,59 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist = {py27,pypy}-{mysql,postgres},pep8
|
envlist = {py27,py35,pypy}-{mysql,postgres},pep8,cover
|
||||||
minversion = 2.0
|
minversion = 2.1
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
setenv = VIRTUAL_ENV={envdir}
|
setenv =
|
||||||
|
VIRTUAL_ENV={envdir}
|
||||||
|
OS_TEST_PATH=tests
|
||||||
|
CLIENT_NAME=monasca-notification
|
||||||
|
passenv = http_proxy
|
||||||
|
HTTP_PROXY
|
||||||
|
https_proxy
|
||||||
|
HTTPS_PROXY
|
||||||
|
no_proxy
|
||||||
|
NO_PROXY
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
install_command =
|
install_command =
|
||||||
{toxinidir}/tools/tox_install.sh {env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} --pre
|
{toxinidir}/tools/tox_install.sh {env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} --pre
|
||||||
whitelist_externals = find
|
whitelist_externals = bash
|
||||||
|
find
|
||||||
|
rm
|
||||||
deps = -r{toxinidir}/requirements.txt
|
deps = -r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
PyMySQL>=0.6.1
|
PyMySQL>=0.6.1
|
||||||
commands =
|
commands =
|
||||||
find . -type f -name "*.pyc" -delete
|
find . -type f -name "*.pyc" -delete
|
||||||
nosetests
|
ostestr {posargs}
|
||||||
|
|
||||||
[testenv:py27-postgres]
|
[testenv:py27-postgres]
|
||||||
deps = -r{toxinidir}/requirements.txt
|
deps = -r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
postgres: psycopg2
|
psycopg2>=2.5
|
||||||
|
|
||||||
|
[testenv:py35-postgres]
|
||||||
|
deps = -r{toxinidir}/requirements.txt
|
||||||
|
-r{toxinidir}/test-requirements.txt
|
||||||
|
psycopg2>=2.5
|
||||||
|
|
||||||
[testenv:pypy-postgres]
|
[testenv:pypy-postgres]
|
||||||
deps = -r{toxinidir}/requirements.txt
|
deps = -r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
postgres: psycopg2
|
psycopg2>=2.5
|
||||||
|
|
||||||
|
[testenv:cover]
|
||||||
|
basepython = python2.7
|
||||||
|
deps = {[testenv]deps}
|
||||||
|
commands =
|
||||||
|
{[testenv]commands}
|
||||||
|
coverage erase
|
||||||
|
python setup.py test --coverage --testr-args='{posargs}' --coverage-package-name=monasca_notification
|
||||||
|
coverage report
|
||||||
|
|
||||||
|
[testenv:debug]
|
||||||
|
commands =
|
||||||
|
oslo_debug_helper -t ./monasca_notification/tests {posargs}
|
||||||
|
|
||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
commands = flake8
|
commands = flake8
|
||||||
|
@ -38,4 +67,4 @@ max-line-length = 120
|
||||||
# H201 no 'except:' at least use 'except Exception:'
|
# H201 no 'except:' at least use 'except Exception:'
|
||||||
# H405 multi line docstring summary not separated with an empty line
|
# H405 multi line docstring summary not separated with an empty line
|
||||||
ignore = F821,H201,H405
|
ignore = F821,H201,H405
|
||||||
exclude=.venv,.git,.tox,dist,*openstack/common*,*egg,build
|
exclude=.venv,.git,.tox,dist,*egg,build
|
||||||
|
|
Loading…
Reference in New Issue