-
Notifications
You must be signed in to change notification settings - Fork 37
Add script for running all tests from inner buildout packages #70
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
Open
Scandie
wants to merge
2
commits into
openprocurement:ea_a499878011598746_separating_awarding
Choose a base branch
from
Scandie:a542055734579786_run_tests
base: ea_a499878011598746_separating_awarding
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| """ | ||
| Example of usage: | ||
|
|
||
| bin/python run_tests.py run tests for packages groups specified in DEFAULT_PACKAGES | ||
| bin/python run_tests.py openprocurement specify packages groups to run tests for | ||
| bin/python run_tests.py --list-packages show packages that will be tested without actually running them | ||
| """ | ||
| import argparse | ||
| import logging | ||
| import os | ||
| from pkg_resources import iter_entry_points | ||
|
|
||
| import nose | ||
|
|
||
| DEFAULT_PACKAGES = ['openprocurement'] # default groups of packages that should be tested | ||
| 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 get_tests(packages, test_type): | ||
| """ | ||
| Collect tests from entry points of specified packages. | ||
| :param packages: list of strings, which are representing groups of packages that should be tested. | ||
| :param test_type: 'tests' or 'pytests' for unittest TestCases and pytest test respectively. | ||
| :return: test suites collected from entry points; | ||
| list of strings, which are representing packages that will be tested. | ||
| """ | ||
| tested_packages = list() | ||
| all_tests = list() | ||
| for pack in packages: | ||
| for entry_point in iter_entry_points(group='{}.{}'.format(pack, test_type)): | ||
| package_name = '{}.{}'.format(pack, entry_point.name) | ||
| tested_packages.append(package_name) | ||
| suite = entry_point.load() | ||
| if test_type == 'tests': | ||
| for tests in suite(): | ||
| all_tests.extend(tests) | ||
| elif test_type == 'pytests': | ||
| all_tests.append(suite) | ||
| return all_tests, tested_packages | ||
|
|
||
|
|
||
| def setup_logger(): | ||
| logger = logging.getLogger('console_output') | ||
| logger.setLevel(logging.INFO) | ||
| console_handler = logging.StreamHandler() | ||
| console_handler.setLevel(logging.INFO) | ||
| logger.addHandler(console_handler) | ||
| return logger | ||
|
|
||
|
|
||
| def list_packages(cover_packages, pytest_packages, logger): | ||
| """ | ||
| Print to console names of packages that will be tested, without running tests. | ||
| """ | ||
| if cover_packages: | ||
| logger.info('NOSETESTS:') | ||
| for p in cover_packages: | ||
| logger.info("> {}".format(p)) | ||
| if pytest_packages: | ||
| logger.info('PYTESTS:') | ||
| for p in pytest_packages: | ||
| logger.info("> {}".format(p)) | ||
|
|
||
|
|
||
| def run(): | ||
| logger = setup_logger() | ||
| 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) | ||
| nose_tests, cover_packages = get_tests(unique_packages, 'tests') | ||
| pytests, pytest_packages = get_tests(unique_packages, 'pytests') | ||
| if args.list_packages: | ||
| list_packages(cover_packages, pytest_packages, logger) | ||
| else: | ||
| NOSE_ENV['NOSE_COVER_PACKAGE'] = cover_packages | ||
| for suite in pytests: | ||
| suite() | ||
| nose.run(suite=nose_tests, env=NOSE_ENV) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| run() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Все це варто в окрему функцію main закинути
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.
І тут викликати.