changeset c6e2112bb45b in cookiecutter:default
details: https://hg.tryton.org/cookiecutter?cmd=changeset&node=c6e2112bb45b
description:
Replace test setuptools command by unittest discover
issue9215
review409111002
diffstat:
{{ cookiecutter.module_name }}/setup.py
| 6 +-
{{ cookiecutter.module_name }}/tests/__init__.py
| 7 -
{{ cookiecutter.module_name }}/tests/test_module.py
| 14 +++
{{ cookiecutter.module_name }}/tests/test_{{ cookiecutter.module_name }}.py
| 36 ----------
{{ cookiecutter.module_name }}/tests/{% if cookiecutter.test_with_scenario
%}test_scenario.py{% endif %} | 22 ++++++
{{ cookiecutter.module_name }}/tox.ini
| 3 +-
6 files changed, 41 insertions(+), 47 deletions(-)
diffs (133 lines):
diff -r dc56d8d31361 -r c6e2112bb45b {{ cookiecutter.module_name }}/setup.py
--- a/{{ cookiecutter.module_name }}/setup.py Sun Apr 10 19:12:00 2022 +0200
+++ b/{{ cookiecutter.module_name }}/setup.py Sat Apr 16 18:30:48 2022 +0200
@@ -159,13 +159,13 @@
license='GPL-3',
python_requires='>=3.7',
install_requires=requires,
+ extras_require={
+ 'test': tests_require,
+ },
dependency_links=dependency_links,
zip_safe=False,
entry_points="""
[trytond.modules]
{{ cookiecutter.module_name }} = trytond.modules.{{
cookiecutter.module_name }}
""", # noqa: E501
- test_suite='tests',
- test_loader='trytond.test_loader:Loader',
- tests_require=tests_require,
)
diff -r dc56d8d31361 -r c6e2112bb45b {{ cookiecutter.module_name
}}/tests/__init__.py
--- a/{{ cookiecutter.module_name }}/tests/__init__.py Sun Apr 10 19:12:00
2022 +0200
+++ b/{{ cookiecutter.module_name }}/tests/__init__.py Sat Apr 16 18:30:48
2022 +0200
@@ -1,11 +1,4 @@
{% if not cookiecutter.prefix -%}
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
-
{% endif -%}
-try:
- from trytond.modules.{{ cookiecutter.module_name
}}.tests.test_{{cookiecutter.module_name }} import suite # noqa: E501, isort:
skip
-except ImportError:
- from .test_{{ cookiecutter.module_name }} import suite
-
-__all__ = ['suite']
diff -r dc56d8d31361 -r c6e2112bb45b {{ cookiecutter.module_name
}}/tests/test_module.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/{{ cookiecutter.module_name }}/tests/test_module.py Sat Apr 16
18:30:48 2022 +0200
@@ -0,0 +1,14 @@
+{% if not cookiecutter.prefix -%}
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+
+{%- endif %}
+from trytond.tests.test_tryton import ModuleTestCase
+
+
+class {{ cookiecutter.module_name.replace('_', ' ').title().replace(' ', '')
}}TestCase(ModuleTestCase):
+ 'Test {{ cookiecutter.module_name.replace('_', ' ').title() }} module'
+ module = '{{ cookiecutter.module_name }}'
+
+
+del ModuleTestCase
diff -r dc56d8d31361 -r c6e2112bb45b {{ cookiecutter.module_name
}}/tests/test_{{ cookiecutter.module_name }}.py
--- a/{{ cookiecutter.module_name }}/tests/test_{{ cookiecutter.module_name
}}.py Sun Apr 10 19:12:00 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-{% if not cookiecutter.prefix -%}
-# This file is part of Tryton. The COPYRIGHT file at the top level of
-# this repository contains the full copyright notices and license terms.
-
-{%- endif %}
-{%- if cookiecutter.test_with_scenario %}
-import doctest
-{%- endif %}
-import unittest
-
-{% if cookiecutter.test_with_scenario -%}
-from trytond.tests.test_tryton import (
- ModuleTestCase, doctest_checker, doctest_teardown)
-{% else -%}
-from trytond.tests.test_tryton import ModuleTestCase
-{% endif -%}
-from trytond.tests.test_tryton import suite as test_suite
-
-
-class {{ cookiecutter.module_name.replace('_', ' ').title().replace(' ', '')
}}TestCase(ModuleTestCase):
- 'Test {{ cookiecutter.module_name.replace('_', ' ').title() }} module'
- module = '{{ cookiecutter.module_name }}'
-
-
-def suite():
- suite = test_suite()
- suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
- {{ cookiecutter.module_name.replace('_', ' ').title().replace(' ',
'') }}TestCase))
- {%- if cookiecutter.test_with_scenario %}
- suite.addTests(doctest.DocFileSuite(
- 'scenario_{{ cookiecutter.module_name }}.rst',
- tearDown=doctest_teardown, encoding='utf-8',
- checker=doctest_checker,
- optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
- {%- endif %}
- return suite
diff -r dc56d8d31361 -r c6e2112bb45b {{ cookiecutter.module_name }}/tests/{% if
cookiecutter.test_with_scenario %}test_scenario.py{% endif %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/{{ cookiecutter.module_name }}/tests/{% if
cookiecutter.test_with_scenario %}test_scenario.py{% endif %} Sat Apr 16
18:30:48 2022 +0200
@@ -0,0 +1,22 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+
+import doctest
+import glob
+import os
+
+from trytond.tests.test_tryton import doctest_checker, doctest_teardown
+
+
+def load_tests(loader, tests, pattern):
+ cwd = os.getcwd()
+ try:
+ os.chdir(os.path.dirname(__file__))
+ for scenario in glob.glob('*.rst'):
+ tests.addTests(doctest.DocFileSuite(
+ scenario, tearDown=doctest_teardown, encoding='utf-8',
+ checker=doctest_checker,
+ optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
+ finally:
+ os.chdir(cwd)
+ return tests
diff -r dc56d8d31361 -r c6e2112bb45b {{ cookiecutter.module_name }}/tox.ini
--- a/{{ cookiecutter.module_name }}/tox.ini Sun Apr 10 19:12:00 2022 +0200
+++ b/{{ cookiecutter.module_name }}/tox.ini Sat Apr 16 18:30:48 2022 +0200
@@ -2,8 +2,9 @@
envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
[testenv]
+extras = test
commands =
- coverage run --include=.*/{{ cookiecutter.module_name }}/* setup.py test
+ coverage run --include=.*/{{ cookiecutter.module_name }}/* -m unittest
discover -s tests
coverage report --include=.*/{{ cookiecutter.module_name }}/*
--omit=*/tests/*
deps =
coverage