Changeset - 8655320fec11
[Not reviewed]
0 5 0
Branko Majic (branko) - 6 years ago 2018-03-02 12:32:27
branko@majic.rs
GC-14: Cleaned-up testing and development configuration and documentation:

- Enforce 100% coverage in tests (fail the tests otherwise).
- Updated development documentation to list:
- How to run tests with coverage.
- How to generate coverage in html format.
- How to build documentation.
- What tests are included when running test via tox.
- Default to running just the unit tests when not passing in any
arguments to pytest.
- Removed use of pytest-flake8.
- Do not run coverage tests by default outside of tox.
- Ensure documentation is built inside of tox environment, and that it
does not pollute the source directory.
- Have all Python interpreters specified in same section in tox
configuration file.
5 files changed with 50 insertions and 18 deletions:
0 comments (0 inline, 0 general)
.coveragerc
Show inline comments
 
[run]
 
include = gimmecert/*
 
\ No newline at end of file
 
include = gimmecert/*
 

	
 
[report]
 
fail_under = 100
 
\ No newline at end of file
docs/development.rst
Show inline comments
 
@@ -67,9 +67,6 @@ Testing
 
Project includes both unit tests (within ``tests/`` directory) , and
 
functional tests (within ``functional_tests/`` directory).
 

	
 
Running the tests will also generate coverage report in HTML format,
 
stored within directory ``coverage/``.
 

	
 
Tests can be run in a number of different ways, depending on what you
 
want to test and how.
 

	
 
@@ -83,21 +80,47 @@ repository root::
 

	
 
  pytest
 

	
 
Tests can be also run with coverage checks. By default coverage is
 
configured to report to standard output. Report will only list files
 
which lack coverage. For each file a percentage will be shown, as well
 
as line numbers that were not covered by tests. To include coverage
 
checks, run tests with::
 

	
 
  pytest --cov
 

	
 
.. warning::
 
   Gimmecert project has 100% coverage requirement. Anything below
 
   will trigger failures when coverage checks are run.
 

	
 
Should you desire to generate coverage report in HTML format, run
 
(coverage report will be put into directory ``coverage/``)::
 

	
 
  pytest --cov --cov-report=html:coverage/
 

	
 
Functional tests must be run explicitly (since they tend to take more
 
time), with::
 

	
 
  pytest functional_tests/
 

	
 
Linting checks are performed as part of testing. Linting checks can
 
easily be run with command::
 
In addition to proper linting, implemented code should be pruned of
 
unused imports and variables. Linting should be conformant to PEP8,
 
with the exception of line length, which is allowed to be up to 160
 
characters. Linting and code sanity checks are not executed
 
automatically, but can easily be run with::
 

	
 
  flake8
 

	
 
Documentation should be buildable at all times. Documentation build
 
can be triggered with a simple::
 

	
 
  cd docs/
 
  make html
 

	
 
Tests can also be run using `tox <https://tox.readthedocs.io/>`_:
 

	
 
.. note::
 
   When running tests via ``tox``, functional tests are included as
 
   well.
 
   When running tests via ``tox``, functional tests and coverage
 
   checks are included as well.
 

	
 
::
 

	
pytest.ini
Show inline comments
 
[pytest]
 
addopts = --flake8 --cov --cov-report=html:coverage
 
\ No newline at end of file
 
addopts = --cov-report=term-missing:skip-covered
 
testpaths = tests/
 
\ No newline at end of file
setup.py
Show inline comments
 
@@ -37,11 +37,10 @@ test_lint_requirements = [
 
    'flake8>=3.5,<3.6',
 
]
 

	
 
test_requirements = test_lint_requirements + [
 
test_requirements = [
 
    'freezegun>=0.3,<0.4',
 
    'pytest>=3.4,<3.5',
 
    'pytest-cov>=2.5,<2.6',
 
    'pytest-flake8>=0.9,<0.10',
 
    'tox>=2.9,<2.10',
 
]
 

	
tox.ini
Show inline comments
 
[tox]
 
envlist = {py34,py35,py36},lint,doc
 

	
 

	
 
[testenv]
 
whitelist_externals =
 
  make
 

	
 
basepython =
 
  doc: python3
 
  lint: python3
 
  py34: python3.4
 
  py35: python3.5
 
  py36: python3.6
 
@@ -15,20 +16,25 @@ deps =
 
  .[test]
 

	
 
commands =
 
  pytest --basetemp={envtmpdir}
 
  pytest --basetemp={envtmpdir} functional_tests/
 
  # Must specify cov-report explicitly, otherwise coverage starts
 
  # going through the tests as well.
 
  pytest --cov --cov-report=term-missing:skip-covered --basetemp={envtmpdir} tests/ functional_tests/
 

	
 
[testenv:lint]
 
basepython = python3
 
deps =
 
  .[testlint]
 
commands =
 
  flake8
 

	
 
[testenv:doc]
 
basepython = python3
 
deps =
 
  .[doc]
 
changedir = {toxinidir}/docs/
 
setenv =
 
  # Override Sphinx build directory so we do not trample over user's
 
  # build in source directory.
 
  BUILDDIR={envtmpdir}/docs_build
 
commands =
 
  make html
 
\ No newline at end of file
 
  # Easier to run than changing directory with separate comand. -e
 
  # will ensure the BUILDDIR gets picked-up and overrides the Makefile
 
  # content.
 
  make -C docs/ -e html
0 comments (0 inline, 0 general)