diff --git a/.travis.yml b/.travis.yml index 9a6846480..36c07311e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.rst b/README.rst index b1e9d7199..787ceb70a 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 3.5, 3.6, 3.7, 3.8 * 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 f50426273..c6bb0c3ba 100644 --- a/tests/test_bake_project.py +++ b/tests/test_bake_project.py @@ -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)) @@ -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 def test_bake_with_apostrophe_and_run_tests(cookies): @@ -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 # def test_bake_and_run_travis_pypi_setup(cookies): @@ -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( @@ -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): diff --git a/{{cookiecutter.project_slug}}/.travis.yml b/{{cookiecutter.project_slug}}/.travis.yml index 0261898af..0316d9c05 100644 --- a/{{cookiecutter.project_slug}}/.travis.yml +++ b/{{cookiecutter.project_slug}}/.travis.yml @@ -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' -%} diff --git a/{{cookiecutter.project_slug}}/CONTRIBUTING.rst b/{{cookiecutter.project_slug}}/CONTRIBUTING.rst index b0eb5832b..693b47e24 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 c63920dbc..37ff72d8b 100644 --- a/{{cookiecutter.project_slug}}/Makefile +++ b/{{cookiecutter.project_slug}}/Makefile @@ -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 @@ -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 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}}/setup.py b/{{cookiecutter.project_slug}}/setup.py index 04054e7fd..368e4d9a3 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', @@ -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, diff --git a/{{cookiecutter.project_slug}}/tox.ini b/{{cookiecutter.project_slug}}/tox.ini index acb47eb7d..ab06faf66 100644 --- a/{{cookiecutter.project_slug}}/tox.ini +++ b/{{cookiecutter.project_slug}}/tox.ini @@ -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} {% else %} -commands = python setup.py test +commands = python -m unittest discover {%- endif %}