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
7
.coveragerc
Normal file
7
.coveragerc
Normal file
@ -0,0 +1,7 @@
|
||||
[run]
|
||||
branch = True
|
||||
source = monasca_notification
|
||||
omit = tests/*
|
||||
|
||||
[report]
|
||||
ignore_errors = True
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -11,3 +11,7 @@ build
|
||||
dist
|
||||
monasca_notification.egg-info
|
||||
.*.sw*
|
||||
|
||||
.testrepository/
|
||||
.coverage
|
||||
cover/
|
||||
|
9
.testr.conf
Normal file
9
.testr.conf
Normal file
@ -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
|
||||
# limitations under the License.
|
||||
|
||||
import six
|
||||
|
||||
import logging
|
||||
import time
|
||||
|
||||
@ -23,25 +25,35 @@ from monasca_notification.plugins import webhook_notifier
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
possible_notifiers = []
|
||||
configured_notifiers = {}
|
||||
statsd_counter = {}
|
||||
possible_notifiers = None
|
||||
configured_notifiers = None
|
||||
statsd_counter = None
|
||||
|
||||
statsd = None
|
||||
statsd_timer = None
|
||||
|
||||
|
||||
def init(statsd_obj):
|
||||
global statsd, statsd_timer
|
||||
global statsd, statsd_timer, \
|
||||
possible_notifiers, configured_notifiers,\
|
||||
statsd_counter
|
||||
|
||||
statsd = statsd_obj
|
||||
statsd_timer = statsd.get_timer()
|
||||
|
||||
possible_notifiers.append(email_notifier.EmailNotifier(log))
|
||||
possible_notifiers.append(webhook_notifier.WebhookNotifier(log))
|
||||
possible_notifiers.append(pagerduty_notifier.PagerdutyNotifier(log))
|
||||
statsd_counter = {}
|
||||
configured_notifiers = {}
|
||||
|
||||
possible_notifiers = [
|
||||
email_notifier.EmailNotifier(log),
|
||||
webhook_notifier.WebhookNotifier(log),
|
||||
pagerduty_notifier.PagerdutyNotifier(log)
|
||||
]
|
||||
|
||||
|
||||
def load_plugins(config):
|
||||
global possible_notifiers
|
||||
|
||||
for plugin_class in config.get("plugins", []):
|
||||
try:
|
||||
possible_notifiers.append(simport.load(plugin_class)(log))
|
||||
@ -50,14 +62,18 @@ def load_plugins(config):
|
||||
|
||||
|
||||
def enabled_notifications():
|
||||
global configured_notifiers
|
||||
|
||||
results = []
|
||||
for key in configured_notifiers:
|
||||
results.append(key.upper())
|
||||
return results
|
||||
|
||||
|
||||
def config(config):
|
||||
formatted_config = {type.lower(): value for type, value in config.iteritems()}
|
||||
def config(cfg):
|
||||
global possible_notifiers, configured_notifiers, statsd_counter
|
||||
|
||||
formatted_config = {t.lower(): v for t, v in six.iteritems(cfg)}
|
||||
for notifier in possible_notifiers:
|
||||
ntype = notifier.type.lower()
|
||||
if ntype in formatted_config:
|
||||
@ -102,6 +118,8 @@ def send_notifications(notifications):
|
||||
|
||||
|
||||
def send_single_notification(notification):
|
||||
global configured_notifiers
|
||||
|
||||
ntype = notification.type
|
||||
try:
|
||||
return configured_notifiers[ntype].send_notification(notification)
|
||||
|
@ -1,10 +1,10 @@
|
||||
# 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
|
||||
# process, which may cause wedges in the gate later.
|
||||
hacking<0.12,>=0.11.0 # Apache-2.0
|
||||
pyflakes==0.8.1 # MIT
|
||||
nose # LGPL
|
||||
nosexcover # BSD
|
||||
# Hacking already pins down pep8, pyflakes and flake8
|
||||
hacking>=0.12.0,!=0.13.0,<0.14 # Apache-2.0
|
||||
coverage>=4.0 # Apache-2.0
|
||||
mock>=2.0 # BSD
|
||||
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
|
||||
|
45
tox.ini
45
tox.ini
@ -1,30 +1,59 @@
|
||||
[tox]
|
||||
envlist = {py27,pypy}-{mysql,postgres},pep8
|
||||
minversion = 2.0
|
||||
envlist = {py27,py35,pypy}-{mysql,postgres},pep8,cover
|
||||
minversion = 2.1
|
||||
skipsdist = True
|
||||
|
||||
[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
|
||||
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
|
||||
whitelist_externals = find
|
||||
whitelist_externals = bash
|
||||
find
|
||||
rm
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
PyMySQL>=0.6.1
|
||||
commands =
|
||||
find . -type f -name "*.pyc" -delete
|
||||
nosetests
|
||||
ostestr {posargs}
|
||||
|
||||
[testenv:py27-postgres]
|
||||
deps = -r{toxinidir}/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]
|
||||
deps = -r{toxinidir}/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]
|
||||
commands = flake8
|
||||
@ -38,4 +67,4 @@ max-line-length = 120
|
||||
# H201 no 'except:' at least use 'except Exception:'
|
||||
# H405 multi line docstring summary not separated with an empty line
|
||||
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
Block a user