From ed1c12c783e74f0226f33ba0a6f20cc6e5b5f396 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sun, 19 Feb 2017 12:46:36 +0100 Subject: Clean up utils/README.md Remove old way of running tests, plus mirror edits. --- utils/README.md | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) (limited to 'utils') diff --git a/utils/README.md b/utils/README.md index c37ab41e6..7aa045ae4 100644 --- a/utils/README.md +++ b/utils/README.md @@ -1,56 +1,61 @@ -# Running Tests (NEW) +# Running Tests Run the command: make ci -to run an array of unittests locally. +to run tests and linting tools. Underneath the covers, we use [tox](http://readthedocs.org/docs/tox/) to manage virtualenvs and run tests. Alternatively, tests can be run using [detox](https://pypi.python.org/pypi/detox/) which allows -for running tests in parallel - +for running tests in parallel. ``` pip install tox detox ``` List the test environments available: + ``` tox -l ``` Run all of the tests with: + ``` tox ``` Run all of the tests in parallel with detox: + ``` detox ``` -Running a particular test environment (python 2.7 flake8 tests in this case): +Run a particular test environment: + ``` -tox -e py27-ansible22-flake8 +tox -e py27-flake8 ``` -Running a particular test environment in a clean virtualenv (python 3.5 pylint -tests in this case): +Run a particular test environment in a clean virtualenv: + ``` -tox -r -e py35-ansible22-pylint +tox -r -e py35-pylint ``` If you want to enter the virtualenv created by tox to do additional -testing/debugging (py27-flake8 env in this case): +testing/debugging: + ``` -source .tox/py27-ansible22-flake8/bin/activate +source .tox/py27-flake8/bin/activate ``` You will get errors if the log files already exist and can not be written to by the current user (`/tmp/ansible.log` and `/tmp/installer.txt`). *We're working on it.* + # Running From Source You will need to setup a **virtualenv** to run from source: @@ -66,17 +71,3 @@ The virtualenv `bin` directory should now be at the start of your You can exit the virtualenv with: $ deactivate - -# Testing (OLD) - -*This section is deprecated, but still works* - -First, run the **virtualenv setup steps** described above. - -Install some testing libraries: (we cannot do this via setuptools due to the version virtualenv bundles) - -$ pip install mock nose - -Then run the tests with: - -$ oo-install/bin/nosetests -- cgit v1.2.3 From 1ac142fa1e785aade8272759d32561fc716e8740 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sun, 19 Feb 2017 14:42:33 +0100 Subject: Replace nose with pytest (utils) --- utils/.coveragerc | 15 ++++++++++++++- utils/setup.cfg | 27 ++++++++++++++++++--------- utils/setup.py | 7 +++---- utils/src/ooinstall/oo_config.py | 2 +- utils/test-requirements.txt | 3 ++- utils/tox.ini | 5 ++++- 6 files changed, 42 insertions(+), 17 deletions(-) (limited to 'utils') diff --git a/utils/.coveragerc b/utils/.coveragerc index e1d918755..7a2554caf 100644 --- a/utils/.coveragerc +++ b/utils/.coveragerc @@ -1,5 +1,18 @@ [run] -omit= +branch = True +omit = */lib/python*/site-packages/* */lib/python*/* /usr/* + setup.py + # TODO(rhcarvalho): this is used to ignore test files from coverage report. + # We can make this less generic when we stick with a single test pattern in + # the repo. + test_*.py + *_tests.py + +[report] +fail_under = 70 + +[html] +directory = cover diff --git a/utils/setup.cfg b/utils/setup.cfg index 862dffd7b..d730cd3b4 100644 --- a/utils/setup.cfg +++ b/utils/setup.cfg @@ -4,15 +4,8 @@ # will need to generate wheels for each Python version that you support. universal=1 -[nosetests] -verbosity=2 -with-coverage=1 -cover-html=1 -cover-inclusive=1 -cover-min-percentage=70 -cover-erase=1 -detailed-errors=1 -cover-branches=1 +[aliases] +test=pytest [flake8] max-line-length=120 @@ -21,3 +14,19 @@ ignore=E501 [lint] lint_disable=fixme,locally-disabled,file-ignored,duplicate-code + +[tool:pytest] +testpaths = test +norecursedirs = + .* + __pycache__ +python_files = + # TODO(rhcarvalho): rename test files to follow a single pattern. "test*.py" + # is Python unittest's default, while pytest discovers both "test_*.py" and + # "*_test.py" by default. + test_*.py + *_tests.py +addopts = + --cov=. + --cov-report=term + --cov-report=html diff --git a/utils/setup.py b/utils/setup.py index 3518581e7..20e3d81dc 100644 --- a/utils/setup.py +++ b/utils/setup.py @@ -40,7 +40,7 @@ setup( # simple. Or you can use find_packages(). #packages=find_packages(exclude=['contrib', 'docs', 'tests*']), packages=['ooinstall'], - package_dir={'ooinstall': 'src/ooinstall'}, + package_dir={'': 'src'}, # List run-time dependencies here. These will be installed by pip when @@ -65,9 +65,8 @@ setup( 'ooinstall': ['ansible.cfg', 'ansible-quiet.cfg', 'ansible_plugins/*'], }, - tests_require=['nose'], - - test_suite='nose.collector', + setup_requires=['pytest-runner'], + tests_require=['pytest'], # To provide executable scripts, use entry points in preference to the # "scripts" keyword. Entry points provide cross-platform support and allow diff --git a/utils/src/ooinstall/oo_config.py b/utils/src/ooinstall/oo_config.py index 9670c03bb..c3501c018 100644 --- a/utils/src/ooinstall/oo_config.py +++ b/utils/src/ooinstall/oo_config.py @@ -176,7 +176,7 @@ class Deployment(object): class OOConfig(object): default_dir = os.path.normpath( os.environ.get('XDG_CONFIG_HOME', - os.environ['HOME'] + '/.config/') + '/openshift/') + os.environ.get('HOME', '') + '/.config/') + '/openshift/') default_file = '/installer.cfg.yml' def __init__(self, config_path): diff --git a/utils/test-requirements.txt b/utils/test-requirements.txt index 699afc26a..b26e22a7e 100644 --- a/utils/test-requirements.txt +++ b/utils/test-requirements.txt @@ -2,7 +2,6 @@ ansible # flake8 moved to before setuptools-lint to satisfy mccabe dependency issue flake8 setuptools-lint -nose coverage mock PyYAML @@ -12,3 +11,5 @@ pyOpenSSL yamllint tox detox +pytest +pytest-cov diff --git a/utils/tox.ini b/utils/tox.ini index 1308f7505..2a29d1525 100644 --- a/utils/tox.ini +++ b/utils/tox.ini @@ -11,6 +11,9 @@ deps = -rtest-requirements.txt py35-flake8: flake8-bugbear commands = + # Needed to make detox work, since it ignores usedevelop + # https://github.com/tox-dev/tox/issues/180 + unit: pip install -e . + unit: pytest flake8: python setup.py flake8 - unit: python setup.py nosetests pylint: python setup.py lint -- cgit v1.2.3 From 7ca7fbdae8ab8fd279a4af9b5d6f140b1aff72e9 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sun, 19 Feb 2017 22:43:56 +0100 Subject: Accept extra positional arguments in tox Example: tox -e py35-ansible22-unit -- --collect-only --- utils/tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils') diff --git a/utils/tox.ini b/utils/tox.ini index 2a29d1525..2524923cb 100644 --- a/utils/tox.ini +++ b/utils/tox.ini @@ -14,6 +14,6 @@ commands = # Needed to make detox work, since it ignores usedevelop # https://github.com/tox-dev/tox/issues/180 unit: pip install -e . - unit: pytest + unit: pytest {posargs} flake8: python setup.py flake8 pylint: python setup.py lint -- cgit v1.2.3 From df1fd5b8f97c69eef10c02f317b62755c4519d92 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Mon, 20 Feb 2017 18:00:23 +0100 Subject: Raise the bar on coverage requirements --- utils/.coveragerc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils') diff --git a/utils/.coveragerc b/utils/.coveragerc index 7a2554caf..551e13192 100644 --- a/utils/.coveragerc +++ b/utils/.coveragerc @@ -12,7 +12,7 @@ omit = *_tests.py [report] -fail_under = 70 +fail_under = 73 [html] directory = cover -- cgit v1.2.3