Skip to content

Commit

Permalink
Merge pull request #123 from dHannasch/run-installed-tests
Browse files Browse the repository at this point in the history
Run installable tests
  • Loading branch information
ionelmc authored Aug 28, 2019
2 parents b6b6357 + 6fc6800 commit 98b269e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ You will be asked for these fields:
- Whether to use the test_runner for python setup.py test.
Note that this will also add to ``setup_requires`` if a test-runner is needed.

* - ``allow_tests_inside_package``
- .. code:: python

"no"
- Run tests in the source directory (that is, tests installed with the package).

* - ``linter``
- .. code:: python

Expand Down
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"test_matrix_separate_coverage": ["no", "yes"],
"test_runner": ["pytest", "nose"],
"test_runner_used_for_setuppy_test": ["no", "yes"],
"allow_tests_inside_package": ["no", "yes"],
"linter": ["flake8", "pylama"],
"command_line_interface": ["plain", "argparse", "click", "no"],
"command_line_interface_bin_name": "{{ cookiecutter.distribution_name }}",
Expand Down
3 changes: 3 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def replace_contents(filename, what, replacement):
{%- if cookiecutter.test_matrix_configurator == 'no' %}
os.unlink(join('ci', 'templates', 'tox.ini'))
{% endif %}
{%- if cookiecutter.allow_tests_inside_package == 'no' %}
shutil.rmtree(join('src', '{{ cookiecutter.package_name }}', 'tests'))
{% endif %}

{%- if cookiecutter.c_extension_support == 'no' %}
os.unlink(join('src', '{{ cookiecutter.package_name }}', '{{ cookiecutter.c_extension_module }}.c'))
Expand Down
25 changes: 24 additions & 1 deletion {{cookiecutter.repo_name}}/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ norecursedirs =
build
migrations
{% else %}
testpaths = tests
norecursedirs =
migrations
{% endif %}
Expand All @@ -72,6 +71,30 @@ addopts =
--doctest-modules
--doctest-glob=\*.rst
--tb=short
{%- if cookiecutter.allow_tests_inside_package == 'yes' %}
--pyargs
testpaths =
{{cookiecutter.package_name}}
tests/
# The order of these options matters. testpaths comes after addopts so that
# {{cookiecutter.package_name}} in testpaths is interpreted as
# --pyargs {{cookiecutter.package_name}}.
# Any tests in the src/ directory (that is, tests installed with the package)
# can be run by any user with pytest --pyargs {{cookiecutter.package_name}}.
# Packages that are sensitive to the host machine, most famously NumPy,
# include tests with the installed package so that any user can check
# at any time that everything is working properly.
# If you do choose to make installable tests, this will run the installed
# tests as they are actually installed (same principle as when we ensure that
# we always test the installed version of the package).
# If you have no need for this (and your src/ directory is very large),
# you can save a few milliseconds on testing by telling pytest not to search
# the src/ directory by removing
# --pyargs and {{cookiecutter.package_name}} from the options here.
{%- else %}
testpaths =
tests
{%- endif %}

{% elif cookiecutter.test_runner == "nose" -%}
[nosetests]
Expand Down
Empty file.

0 comments on commit 98b269e

Please sign in to comment.