Merge "Add a python unit test framework"

This commit is contained in:
Zuul 2018-07-25 20:45:03 +00:00 committed by Gerrit Code Review
commit 3535aa0e43
11 changed files with 42 additions and 2 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
# Unit test / coverage reports
.coverage
.tox
.stestr
# Sphinx
doc/build

3
.stestr.conf Normal file
View File

@ -0,0 +1,3 @@
[DEFAULT]
test_path=./tests
top_dir=./

View File

View File

View File

View File

View File

@ -9,3 +9,4 @@ ansible<2.4
ansible-lint
bashate>=0.2
zuul-sphinx>=0.1.1
stestr>=1.0.0 # Apache-2.0

0
tests/__init__.py Normal file
View File

35
tests/test_discovery.py Normal file
View File

@ -0,0 +1,35 @@
# Copyright 2013 IBM Corp.
#
# 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.
import os
import unittest
def load_tests(loader, tests, pattern):
suite = unittest.TestSuite()
base_path = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
# Load role tests
for role_dir in os.listdir('roles'):
full_role_dir = os.path.join(base_path, 'roles', role_dir)
lib_dir = os.path.join(full_role_dir, 'library')
if not os.path.exists(lib_dir):
continue
if not pattern:
suite.addTests(loader.discover(lib_dir,
top_level_dir=base_path))
else:
suite.addTests(loader.discover(lib_dir, pattern=pattern,
top_level_dir=base_path))
return suite

View File

@ -7,8 +7,8 @@ envlist = linters
basepython = python3
install_command = pip install {opts} {packages}
deps = -r{toxinidir}/test-requirements.txt
commands =
python setup.py testr --slowest --testr-args='{posargs}'
commands = stestr run {posargs}
stestr slowest
[testenv:bindep]
# Do not install any requirements. We want this to be fast and work even if