Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ python:
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install -U tox-travis

# command to run tests, e.g. python setup.py test
# command to run tests, e.g. python -m unittest discover
script: tox

# deploy new versions to PyPI
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Cookiecutter_ template for a Python package.
Features
--------

* Testing setup with ``unittest`` and ``python setup.py test`` or ``pytest``
* Testing setup with ``unittest`` or ``pytest``
* Travis-CI_: Ready for Travis Continuous Integration testing
* Tox_ testing: Setup to easily test for Python 3.5, 3.6, 3.7, 3.8
* Sphinx_ docs: Documentation ready for generation with, for example, ReadTheDocs_
Expand Down
14 changes: 7 additions & 7 deletions tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_bake_with_defaults(cookies):
def test_bake_and_run_tests(cookies):
with bake_in_temp_dir(cookies) as result:
assert result.project.isdir()
run_inside_dir('python setup.py test', str(result.project)) == 0
run_inside_dir('python -m unittest discover', str(result.project)) == 0
print("test_bake_and_run_tests path", str(result.project))


Expand All @@ -98,7 +98,7 @@ def test_bake_withspecialchars_and_run_tests(cookies):
extra_context={'full_name': 'name "quote" name'}
) as result:
assert result.project.isdir()
run_inside_dir('python setup.py test', str(result.project)) == 0
run_inside_dir('python setup.py --help', str(result.project)) == 0

Choose a reason for hiding this comment

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

This doesn't do what the test name says

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right... When I saw the docstring I rationalized that the only reason it was running the tests was to validate that setup.py was formatted correctly. Do you agree/does this accomplish the same objective with less overhead? If so I'll rename it, if not I'll change it to run tests.



def test_bake_with_apostrophe_and_run_tests(cookies):
Expand All @@ -108,7 +108,7 @@ def test_bake_with_apostrophe_and_run_tests(cookies):
extra_context={'full_name': "O'connor"}
) as result:
assert result.project.isdir()
run_inside_dir('python setup.py test', str(result.project)) == 0
run_inside_dir('python setup.py --help', str(result.project)) == 0

Choose a reason for hiding this comment

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

This doesn't do what the test name says

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see previous comments



# def test_bake_and_run_travis_pypi_setup(cookies):
Expand Down Expand Up @@ -220,12 +220,10 @@ def test_using_pytest(cookies):
lines = test_file_path.readlines()
assert "import pytest" in ''.join(lines)
# Test the new pytest target
run_inside_dir('python setup.py pytest', str(result.project)) == 0
# Test the test alias (which invokes pytest)
run_inside_dir('python setup.py test', str(result.project)) == 0
run_inside_dir('python -m pytest ./tests', str(result.project)) == 0


def test_not_using_pytest(cookies):
def test_using_unittest(cookies):
with bake_in_temp_dir(cookies) as result:
assert result.project.isdir()
test_file_path = result.project.join(
Expand All @@ -234,6 +232,8 @@ def test_not_using_pytest(cookies):
lines = test_file_path.readlines()
assert "import unittest" in ''.join(lines)
assert "import pytest" not in ''.join(lines)
# Run tests using unittest
run_inside_dir('python -m unittest discover', str(result.project)) == 0


# def test_project_with_hyphen_in_module_name(cookies):
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ python:
# Command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install -U tox-travis

# Command to run tests, e.g. python setup.py test
# Command to run tests, e.g. tox
script: tox

{% if cookiecutter.use_pypi_deployment_with_travis == 'y' -%}
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Ready to contribute? Here's how to set up `{{ cookiecutter.project_slug }}` for
tests, including testing other Python versions with tox::

$ flake8 {{ cookiecutter.project_slug }} tests
$ python setup.py test or pytest
$ python -m pytest ./tests
$ tox

To get flake8 and tox, just pip install them into your virtualenv.
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test: ## run tests quickly with the default Python
{%- if cookiecutter.use_pytest == 'y' %}
pytest
{%- else %}
python setup.py test
python -m unittest discover
{%- endif %}

test-all: ## run tests on every Python version with tox
Expand All @@ -64,7 +64,7 @@ coverage: ## check code coverage quickly with the default Python
{%- if cookiecutter.use_pytest == 'y' %}
coverage run --source {{ cookiecutter.project_slug }} -m pytest
{%- else %}
coverage run --source {{ cookiecutter.project_slug }} setup.py test
coverage run --source {{ cookiecutter.project_slug }} -m unittest discover
{%- endif %}
coverage report -m
coverage html
Expand Down
7 changes: 0 additions & 7 deletions {{cookiecutter.project_slug}}/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,3 @@ exclude = docs

[aliases]

Choose a reason for hiding this comment

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

I'd remove this section if it's empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left this in to demonstrate how it's done, but I can certainly remove it

# Define setup.py command aliases here
{%- if cookiecutter.use_pytest == 'y' %}
test = pytest

[tool:pytest]
collect_ignore = ['setup.py']
{%- endif %}

6 changes: 0 additions & 6 deletions {{cookiecutter.project_slug}}/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

requirements = [{%- if cookiecutter.command_line_interface|lower == 'click' %}'Click>=7.0',{%- endif %} ]

setup_requirements = [{%- if cookiecutter.use_pytest == 'y' %}'pytest-runner',{%- endif %} ]

test_requirements = [{%- if cookiecutter.use_pytest == 'y' %}'pytest>=3',{%- endif %} ]

{%- set license_classifiers = {
'MIT license': 'License :: OSI Approved :: MIT License',
Expand Down Expand Up @@ -58,9 +55,6 @@
keywords='{{ cookiecutter.project_slug }}',
name='{{ cookiecutter.project_slug }}',
packages=find_packages(include=['{{ cookiecutter.project_slug }}', '{{ cookiecutter.project_slug }}.*']),
setup_requires=setup_requirements,
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}',
version='{{ cookiecutter.version }}',
zip_safe=False,
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.project_slug}}/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ commands = flake8 {{ cookiecutter.project_slug }} tests
[testenv]
setenv =
PYTHONPATH = {toxinidir}
{% if cookiecutter.use_pytest == 'y' -%}
deps =
-r{toxinidir}/requirements_dev.txt
; If you want to make tox run the tests with the same versions, create a
; requirements.txt with the pinned versions and uncomment the following line:
; -r{toxinidir}/requirements.txt
{% if cookiecutter.use_pytest == 'y' -%}
commands =
pip install -U pip
pytest --basetemp={envtmpdir}

Choose a reason for hiding this comment

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

Above, the command was pytest ./tests

Copy link
Contributor Author

@ChadBailey ChadBailey Nov 25, 2019

Choose a reason for hiding this comment

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

I moved this down because requirements_dev.txt needs to be installed irrespective of which test suite is in use.

Edit: I think I'm confused... does L28 need to be changed? I didn't understand the intent of this line but left it unchanged since it was not impacted by the change

{% else %}
commands = python setup.py test
commands = python -m unittest discover
{%- endif %}