From 1676453e63421486fdf87cf742669990608e8e04 Mon Sep 17 00:00:00 2001 From: Chad Bailey Date: Sun, 24 Nov 2019 15:47:12 -0600 Subject: [PATCH 1/3] Removed all references to `setup.py test` fixes #500 --- .travis.yml | 2 +- README.rst | 2 +- tests/test_bake_project.py | 14 +++++++------- {{cookiecutter.project_slug}}/.travis.yml | 2 +- {{cookiecutter.project_slug}}/CONTRIBUTING.rst | 2 +- {{cookiecutter.project_slug}}/Makefile | 4 ++-- {{cookiecutter.project_slug}}/setup.cfg | 7 ------- {{cookiecutter.project_slug}}/tox.ini | 4 ++-- 8 files changed, 15 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index f72bdb37e..b1e1bfe21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,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 diff --git a/README.rst b/README.rst index 156f94eba..93b07ee38 100644 --- a/README.rst +++ b/README.rst @@ -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 2.7, 3.5, 3.6, 3.7 * Sphinx_ docs: Documentation ready for generation with, for example, ReadTheDocs_ diff --git a/tests/test_bake_project.py b/tests/test_bake_project.py index 1c7c94443..c1fd9191b 100644 --- a/tests/test_bake_project.py +++ b/tests/test_bake_project.py @@ -90,7 +90,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)) @@ -98,14 +98,14 @@ def test_bake_withspecialchars_and_run_tests(cookies): """Ensure that a `full_name` with double quotes does not break setup.py""" with bake_in_temp_dir(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 def test_bake_with_apostrophe_and_run_tests(cookies): """Ensure that a `full_name` with apostrophes does not break setup.py""" with bake_in_temp_dir(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 # def test_bake_and_run_travis_pypi_setup(cookies): @@ -184,18 +184,18 @@ 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('tests/test_python_boilerplate.py') 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): diff --git a/{{cookiecutter.project_slug}}/.travis.yml b/{{cookiecutter.project_slug}}/.travis.yml index 2e9d3346c..2f8245a7c 100644 --- a/{{cookiecutter.project_slug}}/.travis.yml +++ b/{{cookiecutter.project_slug}}/.travis.yml @@ -11,7 +11,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' -%} diff --git a/{{cookiecutter.project_slug}}/CONTRIBUTING.rst b/{{cookiecutter.project_slug}}/CONTRIBUTING.rst index f7f4b75f9..9d1426f2d 100644 --- a/{{cookiecutter.project_slug}}/CONTRIBUTING.rst +++ b/{{cookiecutter.project_slug}}/CONTRIBUTING.rst @@ -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. diff --git a/{{cookiecutter.project_slug}}/Makefile b/{{cookiecutter.project_slug}}/Makefile index f5dc90145..a1fad5a56 100644 --- a/{{cookiecutter.project_slug}}/Makefile +++ b/{{cookiecutter.project_slug}}/Makefile @@ -57,7 +57,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 @@ -67,7 +67,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 diff --git a/{{cookiecutter.project_slug}}/setup.cfg b/{{cookiecutter.project_slug}}/setup.cfg index f94db5237..6ead381a2 100644 --- a/{{cookiecutter.project_slug}}/setup.cfg +++ b/{{cookiecutter.project_slug}}/setup.cfg @@ -19,10 +19,3 @@ exclude = docs [aliases] # Define setup.py command aliases here -{%- if cookiecutter.use_pytest == 'y' %} -test = pytest - -[tool:pytest] -collect_ignore = ['setup.py'] -{%- endif %} - diff --git a/{{cookiecutter.project_slug}}/tox.ini b/{{cookiecutter.project_slug}}/tox.ini index 361cc3c24..09921601f 100644 --- a/{{cookiecutter.project_slug}}/tox.ini +++ b/{{cookiecutter.project_slug}}/tox.ini @@ -17,15 +17,15 @@ commands = flake8 {{ cookiecutter.project_slug }} [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} {% else %} -commands = python setup.py test +commands = python -m unittest discover {%- endif %} From 8c49bef09ccd13fdb06cd3ad3d609ba0046d1c87 Mon Sep 17 00:00:00 2001 From: Chad Bailey Date: Thu, 6 Feb 2020 18:23:39 -0600 Subject: [PATCH 2/3] In accordance with deprecation notice of pytest-runner, removing pytest references from setup.py --- {{cookiecutter.project_slug}}/setup.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/setup.py b/{{cookiecutter.project_slug}}/setup.py index 04054e7fd..f5af89adf 100644 --- a/{{cookiecutter.project_slug}}/setup.py +++ b/{{cookiecutter.project_slug}}/setup.py @@ -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', From 89e9a90ff04f5f585a099324630f56863986864a Mon Sep 17 00:00:00 2001 From: Chad Bailey Date: Thu, 6 Feb 2020 19:22:33 -0600 Subject: [PATCH 3/3] Removed test and setup requirements in setup.py --- {{cookiecutter.project_slug}}/setup.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/setup.py b/{{cookiecutter.project_slug}}/setup.py index f5af89adf..368e4d9a3 100644 --- a/{{cookiecutter.project_slug}}/setup.py +++ b/{{cookiecutter.project_slug}}/setup.py @@ -55,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,