Skip to content
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

[RFC] add tox.ini / support for pytest #123

Merged
merged 1 commit into from May 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 27 additions & 15 deletions .travis.yml
Expand Up @@ -5,33 +5,45 @@ cache: pip
services:
- postgresql

python:
- "3.5"
- "3.4"
- "2.7"

env:
- DJANGO="django>=1.10,<1.11"
- DJANGO="django>=1.9,<1.10"
- DJANGO="django>=1.8,<1.9"
matrix:
include:
- python: 3.6
env: TOXENV=py36-django111
- python: 3.6
env: TOXENV=py36-django110
- python: 3.6
env: TOXENV=py36-django19
- python: 3.6
env: TOXENV=py36-django18

- python: 3.5
env: TOXENV=py35-django110

- python: 3.4
env: TOXENV=py34-django110

- python: 2.7
env: TOXENV=py27-django111
- python: 2.7
env: TOXENV=py27-django110
- python: 2.7
env: TOXENV=py27-django19
- python: 2.7
env: TOXENV=py27-django18

branches:
only:
- master

# command to install requirements
install:
- pip install $DJANGO
- pip install -r requirements-test.txt
- python setup.py -q develop
- pip install coverage tox

before_script:
- createdb django_restframework_gis
- psql -U postgres -d django_restframework_gis -c "CREATE EXTENSION postgis;"

# command to run tests, e.g. python setup.py test
script:
- coverage run --source=rest_framework_gis runtests.py
- coverage run --source=rest_framework_gis $(command -v tox)

after_success:
coveralls
51 changes: 42 additions & 9 deletions README.rst
Expand Up @@ -574,25 +574,29 @@ Projects using this package
Running the tests
-----------------

Assuming one has the dependencies installed (restframework and
restframework\_gis), and one of the `Spatial Database server supported
by
GeoDjango <https://docs.djangoproject.com/en/dev/ref/contrib/gis/db-api/#module-django.contrib.gis.db.backends>`__
is up and running:
Required setup
==============

You need one of the `Spatial Database servers supported by
GeoDjango <https://docs.djangoproject.com/en/dev/ref/contrib/gis/db-api/#module-django.contrib.gis.db.backends>`__,
and create a database for the tests.

The following can be used with PostgreSQL:

.. code-block:: bash

./runtests.py
createdb django_restframework_gis
psql -U postgres -d django_restframework_gis -c "CREATE EXTENSION postgis"

You might need to tweak the DB settings according to your DB
configuration. You can copy the file ``local_settings.example.py`` to
``local_settings.py`` and change the ``DATABASES`` and/or
``INSTALLED_APPS`` directives there.

If you want to contribute you need to install the test app in a proper
development environment.
This should allow you to run the tests already.

These steps should do the trick:
For reference, the following steps will setup a development environment for
contributing to the project:

- create a spatial database named "django\_restframework\_gis"
- create ``local_settings.py``, eg:
Expand All @@ -606,6 +610,35 @@ These steps should do the trick:
- run ``python manage.py collectstatic``
- run ``python manage.py runserver``

Using tox
=========

The recommended way to run the tests is by using
`tox <https://tox.readthedocs.io/en/latest/>`__, which can be installed using
`pip install tox`.

You can use ``tox -l`` to list the available environments, and then e.g. use
the following to run all tests with Python 3.6 and Django 1.11:

.. code-block:: bash

tox -e py36-django111

By default Django's test runner is used, but there is a variation of tox's
envlist to use pytest (using the ``-pytest`` suffix).

You can pass optional arguments to the test runner like this:

.. code-block:: bash

tox -e py36-django111-pytest -- -k test_foo

Running tests manually
======================

Please refer to the ``tox.ini`` file for reference/help in case you want to run
tests manually / without tox.

Contributing
------------

Expand Down
Empty file removed tests/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions tox.ini
@@ -0,0 +1,22 @@
[tox]
envlist = py{27,34,35,36,py,py3}-django{18,19,110,111}{,-pytest}

[testenv]
usedevelop = true
setenv =
DJANGO_SETTINGS_MODULE=settings
; Hack: use an environment var to specify the test runner (to avoid using
; "nopytest" as a factor).
DRFG_TEST_RUNNER=python ./tests/manage.py test
pytest: DRFG_TEST_RUNNER=pytest
commands =
{env:DRFG_TEST_RUNNER} {posargs:tests/django_restframework_gis_tests}

deps =
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
django111: Django>=1.11,<2.0
-rrequirements-test.txt
pytest: pytest
pytest: pytest-django