Skip to content

Commit 598f1a8

Browse files
committed
Update test scripts with correct defaults and avoid obsolete functions in setuptools
1 parent 68db378 commit 598f1a8

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

tests/test_bake_project.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import datetime
99
import os
1010
import subprocess
11-
import sys
1211
from cookiecutter.utils import rmtree
1312

1413

@@ -34,6 +33,7 @@ def bake_in_temp_dir(cookies, *args, **kwargs):
3433
cookie to be baked and its temporal files will be removed
3534
"""
3635
result = cookies.bake(*args, **kwargs)
36+
3737
try:
3838
yield result
3939
finally:
@@ -80,15 +80,15 @@ def test_bake_with_defaults(cookies):
8080

8181
found_toplevel_files = [f.basename for f in result.project.listdir()]
8282
assert "setup.py" in found_toplevel_files
83-
assert "pysteps_importer_abc" in found_toplevel_files
83+
assert "pysteps_importer_institution_name" in found_toplevel_files
8484
assert "tox.ini" in found_toplevel_files
8585
assert "tests" in found_toplevel_files
8686

8787

8888
def test_bake_and_run_tests(cookies):
8989
with bake_in_temp_dir(cookies) as result:
9090
assert result.project.isdir()
91-
assert run_inside_dir("python setup.py test", str(result.project)) == 0
91+
assert run_inside_dir("pytest", str(result.project)) == 0
9292

9393

9494
def test_bake_withspecialchars_and_run_tests(cookies):
@@ -97,14 +97,14 @@ def test_bake_withspecialchars_and_run_tests(cookies):
9797
cookies, extra_context={"full_name": 'name "quote" name'}
9898
) as result:
9999
assert result.project.isdir()
100-
assert run_inside_dir("python setup.py test", str(result.project)) == 0
100+
assert run_inside_dir("pytest", str(result.project)) == 0
101101

102102

103103
def test_bake_with_apostrophe_and_run_tests(cookies):
104104
"""Ensure that a `full_name` with apostrophes does not break setup.py"""
105105
with bake_in_temp_dir(cookies, extra_context={"full_name": "O'connor"}) as result:
106106
assert result.project.isdir()
107-
assert run_inside_dir("python setup.py test", str(result.project)) == 0
107+
assert run_inside_dir("pytest", str(result.project)) == 0
108108

109109

110110
def test_bake_selecting_license(cookies):
@@ -137,9 +137,9 @@ def test_bake_not_open_source(cookies):
137137
def test_using_pytest(cookies):
138138
with bake_in_temp_dir(cookies, extra_context={"use_pytest": "y"}) as result:
139139
assert result.project.isdir()
140-
test_file_path = result.project.join("tests/test_pysteps_importer_abc.py")
140+
test_file_path = result.project.join("tests/test_pysteps_importer_institution_name.py")
141141
lines = test_file_path.readlines()
142142
# Test the new pytest target
143-
assert run_inside_dir("python setup.py pytest", str(result.project)) == 0
143+
assert run_inside_dir("pytest", str(result.project)) == 0
144144
# Test the test alias (which invokes pytest)
145-
assert run_inside_dir("python setup.py test", str(result.project)) == 0
145+
assert run_inside_dir("pytest", str(result.project)) == 0

{{cookiecutter.project_name}}/setup.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515

1616
test_requirements = ['pytest>=3']
1717

18+
# Custom command to run tests using pytest
19+
def run_tests():
20+
import pytest
21+
errno = pytest.main(["tests"])
22+
raise SystemExit(errno)
23+
24+
1825
{%- set license_classifiers = {
1926
'MIT license': 'License :: OSI Approved :: MIT License',
2027
'BSD license': 'License :: OSI Approved :: BSD License',
@@ -54,8 +61,6 @@
5461
license="{{ cookiecutter.open_source_license }}",
5562
{%- endif %}
5663
long_description=readme,
57-
test_suite='tests',
58-
tests_require=test_requirements,
5964
include_package_data=True,
6065
keywords=['{{ cookiecutter.project_slug }}', 'pysteps' , 'plugin', '{{ cookiecutter.plugin_type }}'],
6166
name='{{ cookiecutter.project_name }}',
@@ -91,4 +96,7 @@
9196
entry_points = entry,
9297
version='{{ cookiecutter.version }}',
9398
zip_safe=False,
99+
cmdclass = {
100+
'test': run_tests,
101+
},
94102
)

0 commit comments

Comments
 (0)