From fbd235b8af42bfe3df8025b2f7c5e3f1f53b6aef Mon Sep 17 00:00:00 2001 From: Oliver Sauder Date: Tue, 12 Jun 2018 17:22:42 +0200 Subject: [PATCH 1/2] Use tox to run test in travis This way we can harmonize tox and travis configuration --- .gitignore | 2 +- .travis.yml | 46 +++++++++++++++++++--------------------------- setup.cfg | 6 +++++- tox.ini | 9 ++++++++- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index ac41fdd8..5ab2be51 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,7 @@ pip-delete-this-directory.txt .idea/ # PyTest cache -.cache/ +.pytest_cache/ # Tox .tox/ diff --git a/.travis.yml b/.travis.yml index 2a30c0c5..09cd5729 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ ---- language: python sudo: false cache: pip @@ -6,45 +5,38 @@ cache: pip matrix: include: - python: 2.7 - env: DJANGO=">=1.11,<2.0" DRF=">=3.6.3,<3.7" + env: TOXENV=py27-django111-drf36 - python: 2.7 - env: DJANGO=">=1.11,<2.0" DRF=">=3.7.0,<3.8" + env: TOXENV=py27-django111-drf37 - python: 3.4 - env: DJANGO=">=1.11,<2.0" DRF=">=3.6.3,<3.7" + env: TOXENV=py34-django111-drf36 - python: 3.4 - env: DJANGO=">=1.11,<2.0" DRF=">=3.7.0,<3.8" + env: TOXENV=py34-django111-drf37 - python: 3.4 - env: DJANGO=">=2.0,<2.1" DRF=">=3.7.0,<3.8" + env: TOXENV=py34-django20-drf37 - python: 3.5 - env: DJANGO=">=1.11,<2.0" DRF=">=3.6.3,<3.7" + env: TOXENV=py35-django111-drf36 - python: 3.5 - env: DJANGO=">=1.11,<2.0" DRF=">=3.7.0,<3.8" + env: TOXENV=py35-django111-drf37 - python: 3.5 - env: DJANGO=">=2.0,<2.1" DRF=">=3.7.0,<3.8" + env: TOXENV=py35-django20-drf37 - python: 3.6 - env: DJANGO=">=1.11,<2.0" DRF=">=3.6.3,<3.7" + env: TOXENV=py36-django111-drf36 - python: 3.6 - env: DJANGO=">=1.11,<2.0" DRF=">=3.7.0,<3.8" + env: TOXENV=py36-django111-drf37 - python: 3.6 - env: DJANGO=">=2.0,<2.1" DRF=">=3.7.0,<3.8" -before_install: - # Force an upgrade of py & pytest to avoid VersionConflict - - pip install --upgrade py - # Faker requires a newer pytest - - pip install "pytest>3.3" - - pip install codecov flake8 isort + env: TOXENV=py36-django20-drf37 + - python: 3.6 + env: TOXENV=flake8 + - python: 3.6 + env: TOXENV=isort install: - - pip install Django${DJANGO} djangorestframework${DRF} - - python setup.py install + - pip install tox script: - - flake8 - - isort --check-only --verbose --recursive --diff rest_framework_json_api - # example has extra dependencies that are installed in a dev environment - # but are not installed in CI. Explicitly set those packages. - - isort --check-only --verbose --recursive --diff --thirdparty pytest --thirdparty polymorphic --thirdparty pytest_factoryboy --thirdparty packaging example - - coverage run setup.py -v test + - tox after_success: - - codecov + - pip install codecov + - codecov -e TOXENV diff --git a/setup.cfg b/setup.cfg index 10bd79e4..6b206f6f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,7 +7,11 @@ universal = 1 [flake8] ignore = F405 max-line-length = 100 -exclude = docs/conf.py,build,migrations +exclude = + docs/conf.py, + build, + migrations, + .tox, [isort] indent = 4 diff --git a/tox.ini b/tox.ini index dc7470e0..cd161419 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,12 @@ [tox] envlist = py{27,34,35,36}-django111-drf{36,37}, + py{34,35,36}-django20-drf{37}, [testenv] deps = django111: Django>=1.11,<1.12 + django20: Django>=2.0,<2.1 drf36: djangorestframework>=3.6.3,<3.7 drf37: djangorestframework>=3.7.0,<3.8 @@ -15,6 +17,11 @@ setenv = commands = python setup.py test {posargs} +[testenv:flake8] +deps = flake8 +commands = flake8 +skip_install = true + [testenv:isort] deps = isort @@ -22,4 +29,4 @@ commands = isort --check-only --verbose --recursive --diff rest_framework_json_api # example has extra dependencies that are installed in a dev environment # but are not installed in CI. Explicitly set those packages. - isort --check-only --verbose --recursive --diff --thirdparty pytest --thirdparty polymorphic --thirdparty pytest_factoryboy example + isort --check-only --verbose --recursive --diff --thirdparty pytest --thirdparty polymorphic --thirdparty pytest_factoryboy --thirdparty packaging example From 0f01240b5814b2d83ace72e1b61c552eaaccfaae Mon Sep 17 00:00:00 2001 From: Oliver Sauder Date: Wed, 13 Jun 2018 10:38:29 +0200 Subject: [PATCH 2/2] Integrate coverage with pytest-cov --- .gitignore | 3 +++ setup.cfg | 6 ++++++ setup.py | 1 + tox.ini | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5ab2be51..1207cc48 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,9 @@ pip-delete-this-directory.txt # PyTest cache .pytest_cache/ +# Coverage +.coverage + # Tox .tox/ .cache/ diff --git a/setup.cfg b/setup.cfg index 6b206f6f..0e89958c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,3 +22,9 @@ known_standard_library = mock line_length = 100 multi_line_output = 3 skip_glob=*migrations* + +[coverage:report] +omit= + .tox/* + .eggs/* +show_missing = True diff --git a/setup.py b/setup.py index c99639a0..7ff381e2 100755 --- a/setup.py +++ b/setup.py @@ -108,6 +108,7 @@ def get_package_data(package): 'factory-boy', 'pytest-django', 'pytest', + 'pytest-cov', 'django-polymorphic>=2.0', 'packaging', 'django-debug-toolbar' diff --git a/tox.ini b/tox.ini index cd161419..c5c341fb 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ setenv = DJANGO_SETTINGS_MODULE=example.settings.test commands = - python setup.py test {posargs} + python setup.py test --addopts '--cov --no-cov-on-fail' {posargs} [testenv:flake8] deps = flake8