diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5b605ed0..652577ee 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,7 +30,8 @@ The sections below outline the steps in each case. 1. (**important**) announce your plan to the rest of the community _before you start working_. This announcement should be in the form of a (new) issue; 1. (**important**) wait until some kind of consensus is reached about your idea being a good idea; 1. if needed, fork the repository to your own Github profile and create your own feature branch off of the latest main commit. While working on your feature branch, make sure to stay up to date with the main branch by pulling in changes, possibly from the 'upstream' repository (follow the instructions [here](https://help.github.com/articles/configuring-a-remote-for-a-fork/) and [here](https://help.github.com/articles/syncing-a-fork/)); -1. make sure the existing tests still work by running ``python setup.py test``; +1. Install dependencies with `pip3 install -r requirements.txt`; +1. make sure the existing tests still work by running ``pytest``. If project tests fails use ``pytest --keep-baked-projects`` to keep generated project in /tmp/pytest-* and investigate; 1. add your own tests (if necessary); 1. update or expand the documentation; 1. [push](http://rogerdudler.github.io/git-guide/) your feature branch to (your fork of) the Python Template repository on GitHub; diff --git a/tests/test_project.py b/tests/test_project.py index 826596c0..e1eca14e 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -1,4 +1,6 @@ -import pytest +import os +import subprocess +import shlex def test_project_folder(cookies): @@ -8,3 +10,27 @@ def test_project_folder(cookies): assert project.exception is None assert project.project.basename == 'my-python-project' assert project.project.isdir() + + +def run(command: str, dirpath: os.PathLike) -> subprocess.CompletedProcess: + return subprocess.run(shlex.split(command), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=dirpath, + text=True) + + +def test_pytest(cookies): + result = cookies.bake() + env_output = run('python3 -m venv env', result.project) + assert env_output.returncode == 0 + latest_pip_output = run('env/bin/pip3 install --upgrade pip setuptools', result.project) + assert latest_pip_output.returncode == 0 + pip_output = run('env/bin/pip3 install --editable .[dev]', result.project) + assert pip_output.returncode == 0 + + pytest_output = run('env/bin/pytest', result.project) + assert pytest_output.returncode == 0 + assert '== 3 passed in' in pytest_output.stdout + assert (result.project / 'coverage.xml').exists() + assert (result.project / 'htmlcov/index.html').exists() diff --git a/{{cookiecutter.project_name}}/.github/workflows/build.yml b/{{cookiecutter.project_name}}/.github/workflows/build.yml index 1b296cf6..bbd48e0d 100644 --- a/{{cookiecutter.project_name}}/.github/workflows/build.yml +++ b/{{cookiecutter.project_name}}/.github/workflows/build.yml @@ -39,6 +39,4 @@ jobs: run: prospector -0 -o grouped -o pylint:pylint-report.txt - name: Test shell: bash -l {0} - run: | - pytest tests - pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml + run: pytest diff --git a/{{cookiecutter.project_name}}/CONTRIBUTING.rst b/{{cookiecutter.project_name}}/CONTRIBUTING.rst index 3166d760..9f6afd15 100644 --- a/{{cookiecutter.project_name}}/CONTRIBUTING.rst +++ b/{{cookiecutter.project_name}}/CONTRIBUTING.rst @@ -35,7 +35,7 @@ You want to make some kind of change to the code base #. (**important**) announce your plan to the rest of the community *before you start working*. This announcement should be in the form of a (new) issue; #. (**important**) wait until some kind of consensus is reached about your idea being a good idea; #. if needed, fork the repository to your own Github profile and create your own feature branch off of the latest main commit. While working on your feature branch, make sure to stay up to date with the main branch by pulling in changes, possibly from the 'upstream' repository (follow the instructions `here `__ and `here `__); -#. make sure the existing tests still work by running ``python setup.py test``; +#. make sure the existing tests still work by running ``pytest``; #. add your own tests (if necessary); #. update or expand the documentation; #. `push `_ your feature branch to (your fork of) the {{ cookiecutter.project_name }} repository on GitHub; diff --git a/{{cookiecutter.project_name}}/README.rst b/{{cookiecutter.project_name}}/README.rst index ff4e1a26..c8eef9fd 100644 --- a/{{cookiecutter.project_name}}/README.rst +++ b/{{cookiecutter.project_name}}/README.rst @@ -92,7 +92,7 @@ The project setup is documented in `a separate document `_. F Installation ------------ -To install {{ cookiecutter.package_name }}, do: +To install {{ cookiecutter.package_name }} from GitHub repository, do: .. code-block:: console @@ -100,14 +100,6 @@ To install {{ cookiecutter.package_name }}, do: cd {{ cookiecutter.project_name }} python3 -m pip install . - -Run tests (including coverage) with: - -.. code-block:: console - - python3 setup.py test - - Documentation ************* diff --git a/{{cookiecutter.project_name}}/project_setup.md b/{{cookiecutter.project_name}}/project_setup.md index 0256fe5f..d3ff6273 100644 --- a/{{cookiecutter.project_name}}/project_setup.md +++ b/{{cookiecutter.project_name}}/project_setup.md @@ -56,14 +56,13 @@ help you decide which tool to use for packaging. - Tests should be put in the `tests` folder. - The `tests` folder contains: - Example tests that you should replace with your own meaningful tests (file: `test_my_module.py`) - - A test that checks whether your code conforms to the Python style guide (PEP 8) (file: `test_lint.py`) - The testing framework used is [PyTest](https://pytest.org) - [PyTest introduction](http://pythontesting.net/framework/pytest/pytest-introduction/) -- Tests can be run with `python setup.py test` - - This is configured in `setup.py` and `setup.cfg` -- Use [Travis CI](https://travis-ci.com/) to automatically run tests and to test using multiple Python versions - - Configuration can be found in `.travis.yml` - - [Getting started with Travis CI](https://docs.travis-ci.com/user/getting-started/) + - PyTest can be installed with `pip3 install --editable .[dev]` +- Tests can be run with `pytest` + - This is configured in `setup.cfg` +- Use [GitHub action workflow](https://docs.github.com/en/actions) to automatically run tests on GitHub infrastructure against multiple Python versions + - Workflow can be found in [`.github/workflows/build.yml`](.github/workflows/build.yml) - [Relevant section in the guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=testing) ## Documentation @@ -87,7 +86,7 @@ help you decide which tool to use for packaging. ## Coding style conventions and code quality - Check your code style with `prospector` -- You may need run `pip install .[dev]` first, to install the required dependencies +- You may need run `pip install --editable .[dev]` first, to install the required dependencies - You can use `yapf` to fix the readability of your code style and `isort` to format and group your imports - [Relevant section in the guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=coding-style-conventions) diff --git a/{{cookiecutter.project_name}}/setup.cfg b/{{cookiecutter.project_name}}/setup.cfg index d16aa772..503f8d72 100644 --- a/{{cookiecutter.project_name}}/setup.cfg +++ b/{{cookiecutter.project_name}}/setup.cfg @@ -4,11 +4,6 @@ # - https://www.python.org/dev/peps/pep-0314/ -[aliases] -# Define `python setup.py test` -test=pytest - - [metadata] author = {{ cookiecutter.full_name }} author_email = {{ cookiecutter.email }}