From faf755a43273d741b2de078e909668111f219d98 Mon Sep 17 00:00:00 2001 From: Pavel Savchenko Date: Sun, 24 May 2015 08:38:58 +0200 Subject: [PATCH 1/2] refactor out test requirements from tox.ini into their own file --- tests/test_requirements.txt | 4 ++++ tox.ini | 1 + 2 files changed, 5 insertions(+) create mode 100644 tests/test_requirements.txt diff --git a/tests/test_requirements.txt b/tests/test_requirements.txt new file mode 100644 index 00000000..ddefbe8b --- /dev/null +++ b/tests/test_requirements.txt @@ -0,0 +1,4 @@ +mock==1.0.1 +factory-boy==2.5.2 +pytest-django +pytest-cov \ No newline at end of file diff --git a/tox.ini b/tox.ini index d6ab0f02..8512cffb 100644 --- a/tox.ini +++ b/tox.ini @@ -4,6 +4,7 @@ envlist = py27,py33,py34 [testenv] + setenv = DJANGO_SETTINGS_MODULE = localshop.settings DJANGO_CONFIGURATION=TestConfig From 38d404f7baeb95926d78eaae3f2d48ed982c12bc Mon Sep 17 00:00:00 2001 From: Pavel Savchenko Date: Sun, 24 May 2015 11:25:42 +0200 Subject: [PATCH 2/2] :book: contributing: explain more about tests * rebase with latest develop tree * add paragraphs about tox, pyenv and py.test --- .python-version | 3 +++ docs/contributing.rst | 53 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 .python-version diff --git a/.python-version b/.python-version new file mode 100644 index 00000000..70cb7c91 --- /dev/null +++ b/.python-version @@ -0,0 +1,3 @@ +2.7.10 +3.3.6 +3.4.3 diff --git a/docs/contributing.rst b/docs/contributing.rst index e8c11a51..6e69a3a3 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -32,16 +32,57 @@ Get started Running Tests ------------- -To run all tests, simply use `tox`:: +To run all tests, simply use `tox`_: + + .. code-block:: bash pip install tox - tox # use `tox -r` to rebuild the virtual environment + tox -e py27 # use `tox -e py27 -r` to rebuild the virtual environment + + +To run a specific test, pass the test module filename as an argument: + + .. code-block:: bash + + tox -e py27 tests/apps/packages/test_models.py + + +If you would like `tox`_ to run tests for all supported python versions, you should first `install pyenv`_. + +After installing `pyenv`_ you should download all required python versions (see .python-version), and then simply run `tox`_ without the `-e` argument; e.g: + + + .. code-block:: bash + + # install pyenv + curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash + + # install all required python versions + cat .python-version | xargs -I{} pyenv install {} + + # run all tests + tox + + +`tox`_ automatically creates an environment and installs dependencies on each run. When actively developing, you may want to reuse your existing environment to quickly rerun the tests. In this case first install the test dependencies and +then run `py.test`_ directly. E.g : + + .. code-block:: bash + + # recommended: set up a virtual environment + localshop $ virtualenv -a . -r requirements.txt localshop + # install the requirements + (localshop) localshop $ pip install -r requirements.txt + (localshop) localshop $ pip install -e .[test] -To run a specific test, pass the test module filename as an argument:: + # run the tests for the module you are working on + (localshop) localshop (develop)$ py.test tests/apps/packages/test_models.py - tox tests/apps/packages/test_models.py + ================================= test session starts ================================= + ... + ============================== 3 passed in 0.92 seconds =============================== Style guide @@ -123,6 +164,10 @@ Commit messages .. [#rf1] :ref:`installation-instructions` .. _`Squash your commits`: http://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Squashing-Commits +.. _`tox`: https://tox.readthedocs.org/en/latest/ +.. _`install pyenv`: https://github.com/yyuu/pyenv#installation +.. _`pyenv`: https://github.com/yyuu/pyenv +.. _`py.test`: http://pytest.org/latest/ .. _`pull request`: https://help.github.com/articles/using-pull-requests/ .. _`use emojis`: http://www.emoji-cheat-sheet.com .. _PEP8: https://www.python.org/dev/peps/pep-0008/ \ No newline at end of file