-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add script for running all tests from inner buildout packages #70
base: ea_a499878011598746_separating_awarding
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import sys | ||
import os | ||
import nose | ||
import argparse | ||
from pkg_resources import iter_entry_points | ||
import logging | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP 8 |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP 8 |
||
DEFAULT_PACKAGES = ['openprocurement'] # default packages that should be tested | ||
DEFAULT_RECURSION_LIMIT = 1000 | ||
NOSE_ENV = { | ||
"NOSE_WITH_XUNIT": 1, | ||
"NOSE_WITH_COVERAGE": 1, | ||
"NOSE_COVER_PACKAGE": [], | ||
"NOSE_COVER_ERASE": 1, | ||
"NOSE_COVER_HTML": 1, | ||
"NOSE_PROCESSES": 0, | ||
"NOSE_WITH_DOCTEST": 1, | ||
"NOSE_NOCAPTURE": 1, | ||
"NOSE_VERBOSE": 1, | ||
} | ||
os.environ['PYTEST_ADDOPTS'] = '--ignore=src/ --junitxml=pytest.xml' | ||
|
||
|
||
def set_recursion_limit(tests_amount): | ||
""" | ||
Increase default python recursion depth limit | ||
if tests amount is greater than that value | ||
""" | ||
if (DEFAULT_RECURSION_LIMIT - tests_amount) < DEFAULT_RECURSION_LIMIT / 2: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Якщо більше половини, то ми збільшуємо ? Чому саме так ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Немає фіксованої залежності глибини рекурсії від кількості тестів. |
||
sys.setrecursionlimit(tests_amount + DEFAULT_RECURSION_LIMIT) | ||
|
||
|
||
def get_tests(packages, test_type): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstring |
||
tested_packages = list() | ||
all_tests = list() | ||
for pack in packages: | ||
group = pack.split('.')[0] if pack.split('.')[0:1] else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Якась трохи дивна перевірка. Які значення можуть бути тут |
||
if group is None: | ||
continue | ||
for entry_point in iter_entry_points(group=group + '.' + test_type): | ||
package_name = group + '.{}' | ||
package_name = package_name.format(entry_point.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В одному |
||
tested_packages.append(package_name) | ||
suite = entry_point.load() | ||
if package_name.startswith(pack): | ||
if test_type == 'tests': | ||
for tests in suite(): | ||
all_tests.append(tests) | ||
elif test_type == 'pytests': | ||
all_tests.append(suite) | ||
return all_tests, tested_packages | ||
|
||
|
||
def unpack_suites(suites): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstring |
||
tests = list() | ||
for suite in suites: | ||
if hasattr(suite, '_tests'): | ||
tests += unpack_suites(suite._tests) | ||
else: | ||
tests.append(suite) | ||
return tests | ||
|
||
|
||
if __name__ == '__main__': | ||
logger = logging.getLogger('console_output') | ||
logger.setLevel(logging.INFO) | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(logging.INFO) | ||
logger.addHandler(console_handler) | ||
parser = argparse.ArgumentParser(description='Test some packages.') | ||
parser.add_argument('packages', metavar='P', type=str, nargs='*', | ||
help='name of packages to test', default=DEFAULT_PACKAGES) | ||
parser.add_argument('--list-packages', dest='list_packages', action='store_const', | ||
const=True, default=False, | ||
help='List packages that can be tested') | ||
args = parser.parse_args() | ||
unique_packages = set(args.packages) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Все це варто в окрему функцію main закинути There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. І тут викликати. |
||
nose_tests, cover_packages = get_tests(unique_packages, 'tests') | ||
pytests, pytest_packages = get_tests(unique_packages, 'pytests') | ||
if args.list_packages: | ||
logger.info('NOSETESTS:') | ||
for p in cover_packages: | ||
logger.info("> {}".format(p)) | ||
logger.info('PYTESTS:') | ||
for p in pytest_packages: | ||
logger.info("> {}".format(p)) | ||
exit() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Навіщо тут There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yarsanich, для того, щоб зупинити виконання скрипта. Опція |
||
NOSE_ENV['NOSE_COVER_PACKAGE'] = cover_packages | ||
unpacked_tests = unpack_suites(nose_tests) | ||
set_recursion_limit(len(unpacked_tests)) | ||
sys.exit([suite() for suite in pytests], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generator expression тут не підійде ? |
||
nose.run_exit(suite=unpacked_tests, env=NOSE_ENV)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example usage додати сюди і
README
.