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

Remove test command in favor of tox #480

Merged
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: 20 additions & 22 deletions CONTRIBUTING.rst
Expand Up @@ -105,10 +105,15 @@ Now you can make your changes locally.

5. When you're done making changes, check that your changes pass the tests and flake8::

$ flake8 cookiecutter tests
$ python setup.py test
$ pip install tox
$ tox

Please note that tox runs flake8 automatically, since we have a test environment for it.

If you feel like running only the flake8 environment, please use the following command::

$ tox -e flake8

6. Commit your changes and push your branch to GitHub::

$ git add .
Expand All @@ -117,11 +122,10 @@ Now you can make your changes locally.

7. Check that the test coverage hasn't dropped::

coverage run --source cookiecutter setup.py test
coverage report -m
coverage html
$ tox -e cov-report

8. Submit a pull request through the GitHub website.
8. Submit a pull request through the GitHub website.

Contributor Guidelines
-----------------------

Expand All @@ -134,7 +138,7 @@ Before you submit a pull request, check that it meets these guidelines:
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.
3. The pull request should work for Python 2.6, 2.7, 3.3, and PyPy on Appveyor and Travis CI.
3. The pull request should work for Python 2.7, 3.3, 3.4, and PyPy on Appveyor and Travis CI.
4. Check https://travis-ci.org/audreyr/cookiecutter/pull_requests and
https://ci.appveyor.com/project/audreyr/cookiecutter/history to ensure the tests pass for all supported Python versions and platforms.

Expand Down Expand Up @@ -167,33 +171,26 @@ Coding Standards

* Write new code in Python 3.

Testing
-------

To run a particular test::

$ python -m unittest tests.test_find.TestFind.test_find_template

To run a subset of tests::
Testing with tox
----------------

$ python -m unittest tests.test_find
Tox uses py.test under the hood, hence it supports the same syntax for selecting tests.

Testing with py.test
--------------------
For further information please consult the `pytest usage docs`_.

To run a particular test class with py.test::
To run a particular test class with tox::

$ py.test -k TestGetConfig
$ tox -e py '-k TestFindHooks'

To run some tests with names matching a string expression::

$ py.test -k generate
$ tox -e py '-k generate'

Will run all tests matching "generate", test_generate_files for example.

To run just one method::

$ py.test -k TestGetConfig::test_get_config
$ tox -e py '-k "TestFindHooks and test_find_hook"'


To run all tests using various versions of python in virtualenvs defined in tox.ini, just run tox.::
Expand All @@ -220,6 +217,7 @@ Python 3.3 tests fail locally
Try upgrading Tox to the latest version. I noticed that they were failing
locally with Tox 1.5 but succeeding when I upgraded to Tox 1.7.1.

.. _`pytest usage docs`: https://pytest.org/latest/usage.html#specifying-tests-selecting-tests

Core Committer Guide
====================
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Expand Up @@ -27,16 +27,14 @@ lint:
flake8 cookiecutter tests

test:
python setup.py test
tox -e py

test-all:
tox


coverage:
coverage run --source cookiecutter setup.py test
coverage report -m
coverage html
tox -e cov-report
open htmlcov/index.html

docs:
Expand Down
4 changes: 1 addition & 3 deletions cookiecutter/compat.py
Expand Up @@ -8,7 +8,6 @@
if PY3: # pragma: no cover
input_str = 'builtins.input'
iteritems = lambda d: iter(d.items())
from unittest.mock import patch
from io import StringIO


Expand All @@ -17,7 +16,6 @@
input = raw_input
input_str = '__builtin__.raw_input'
iteritems = lambda d: d.iteritems()
from mock import patch
from cStringIO import StringIO


Expand Down Expand Up @@ -101,4 +99,4 @@ def is_string(obj):
return isinstance(obj, str if PY3 else basestring)


_hush_pyflakes = (patch, StringIO, which)
_hush_pyflakes = (StringIO, which)
15 changes: 9 additions & 6 deletions docs/contributor_setup.rst
Expand Up @@ -22,10 +22,15 @@ Now you can make your changes locally.

5. When you're done making changes, check that your changes pass the tests and flake8::

$ flake8 cookiecutter tests
$ python setup.py test
$ pip install tox
$ tox

Please note that tox runs flake8 automatically, since we have a test environment for it.

If you feel like running only the flake8 environment, please use the following command::

$ tox -e flake8

6. Commit your changes and push your branch to GitHub::

$ git add .
Expand All @@ -34,8 +39,6 @@ Now you can make your changes locally.

7. Check that the test coverage hasn't dropped::

coverage run --source cookiecutter setup.py test
coverage report -m
coverage html
$ tox -e cov-report

8. Submit a pull request through the GitHub website.
8. Submit a pull request through the GitHub website.
24 changes: 9 additions & 15 deletions docs/contributor_testing.rst
@@ -1,30 +1,23 @@
Testing
-------
Testing with tox
----------------

To run a particular test::
Tox uses py.test under the hood, hence it supports the same syntax for selecting tests.

$ python -m unittest tests.test_find.TestFind.test_find_template
For further information please consult the `pytest usage docs`_.

To run a subset of tests::
To run a particular test class with tox::

$ python -m unittest tests.test_find

Testing with py.test
--------------------

To run a particular test class with py.test::

$ py.test -k TestGetConfig
$ tox -e py '-k TestFindHooks'

To run some tests with names matching a string expression::

$ py.test -k generate
$ tox -e py '-k generate'

Will run all tests matching "generate", test_generate_files for example.

To run just one method::

$ py.test -k TestGetConfig::test_get_config
$ tox -e py '-k "TestFindHooks and test_find_hook"'


To run all tests using various versions of python in virtualenvs defined in tox.ini, just run tox.::
Expand All @@ -51,3 +44,4 @@ Python 3.3 tests fail locally
Try upgrading Tox to the latest version. I noticed that they were failing
locally with Tox 1.5 but succeeding when I upgraded to Tox 1.7.1.

.. _`pytest usage docs`: https://pytest.org/latest/usage.html#specifying-tests-selecting-tests
32 changes: 2 additions & 30 deletions setup.py
Expand Up @@ -4,9 +4,9 @@
import sys

try:
from setuptools import setup, Command
from setuptools import setup
except ImportError:
from distutils.core import setup, Command
from distutils.core import setup

version = "1.0.0"

Expand All @@ -33,38 +33,13 @@
'click<5.0'
]

test_requirements = [
'pytest'
]

# Add Python 2.7-specific dependencies
if sys.version < '3':
requirements.append('mock')

# There are no Python 3-specific dependencies to add

long_description = readme + '\n\n' + history

if sys.argv[-1] == 'readme':
print(long_description)
sys.exit()


class PyTest(Command):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]

def initialize_options(self):
self.pytest_args = []

def finalize_options(self):
pass

def run(self):
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)


setup(
name='cookiecutter',
version=version,
Expand Down Expand Up @@ -109,7 +84,4 @@ def run(self):
'skeleton, scaffolding, project directory, setup.py, package, '
'packaging'
),
cmdclass = {'test': PyTest},
test_suite='tests',
tests_require=test_requirements
)
15 changes: 4 additions & 11 deletions tox.ini
Expand Up @@ -3,24 +3,17 @@ envlist = py27, py33, py34, pypy, flake8

[testenv]
passenv = LC_ALL, LANG
commands = py.test --cov cookiecutter {posargs:tests}
commands = py.test --cov=cookiecutter {posargs:tests}
deps = pytest
pytest-cov
pytest-mock

[testenv:py27]
deps =
{[testenv]deps}
mock

[testenv:pypy]
deps =
{[testenv]deps}
mock

[testenv:flake8]
deps =
flake8==2.3.0
pep8==1.6.2
commands =
flake8 cookiecutter

[testenv:cov-report]
commands = py.test --cov=cookiecutter --cov-report=term --cov-report=html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing the way you're using --cov here, makes me think that https://github.com/hackebrot/cookiecutter/blob/remove-test-command-in-favor-of-tox/tox.ini#L6 is incorrect?