From fa117863c14218a1f16a897c702a2a7defccafd7 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Tue, 20 Apr 2021 09:21:30 +0200 Subject: [PATCH 1/9] Remove setup.py alias --- {{cookiecutter.project_name}}/setup.cfg | 5 ----- 1 file changed, 5 deletions(-) diff --git a/{{cookiecutter.project_name}}/setup.cfg b/{{cookiecutter.project_name}}/setup.cfg index c32321c9..0adc8ebe 100644 --- a/{{cookiecutter.project_name}}/setup.cfg +++ b/{{cookiecutter.project_name}}/setup.cfg @@ -59,11 +59,6 @@ dev = # It remains empty for now # Check if MANIFEST.in works for your purposes - -[aliases] -# Define `python setup.py test` -test=pytest - [coverage:run] branch = True source = {{ cookiecutter.package_name }} From 60e2961dae72299c3a88de868a4aac63624ecda2 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Tue, 20 Apr 2021 09:23:56 +0200 Subject: [PATCH 2/9] Remove test command from README README is for users not developers of the package. --- {{cookiecutter.project_name}}/README.rst | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/{{cookiecutter.project_name}}/README.rst b/{{cookiecutter.project_name}}/README.rst index a4b94c05..6c738ecc 100644 --- a/{{cookiecutter.project_name}}/README.rst +++ b/{{cookiecutter.project_name}}/README.rst @@ -90,7 +90,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 @@ -98,14 +98,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 ************* From 284e696cdee9a87c3d5443854b8574367baa0029 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Tue, 20 Apr 2021 09:25:04 +0200 Subject: [PATCH 3/9] Use pytest instead of python setup.py test Also rewrote testing chapter to be up to date with current features --- {{cookiecutter.project_name}}/CONTRIBUTING.rst | 2 +- {{cookiecutter.project_name}}/project_setup.md | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) 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}}/project_setup.md b/{{cookiecutter.project_name}}/project_setup.md index 5c4ea292..2c209705 100644 --- a/{{cookiecutter.project_name}}/project_setup.md +++ b/{{cookiecutter.project_name}}/project_setup.md @@ -57,15 +57,14 @@ help you decide which tool to use for packaging. - 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 @@ -97,7 +96,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 +- You may need run `pip3 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 From ed32be2d4580259716b5f8dc8ebbb3f8e18395ce Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Tue, 20 Apr 2021 09:25:58 +0200 Subject: [PATCH 4/9] Use same command in GH workflow as in CONTRIBUTING As setup.cfg already switches on coverage --- {{cookiecutter.project_name}}/.github/workflows/build.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 From 7e1da1e37cc76dc01f01b4d6930ca1128f3c528d Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Tue, 20 Apr 2021 09:59:10 +0200 Subject: [PATCH 5/9] Added test to run pytest of baked project --- tests/test_project.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/test_project.py b/tests/test_project.py index 826596c0..775a1693 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,25 @@ 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 + 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() From a7ceb324518f164d172105e7f2e03772882cdc68 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Tue, 20 Apr 2021 11:46:39 +0200 Subject: [PATCH 6/9] Force latest pip setuptools --- tests/test_project.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_project.py b/tests/test_project.py index 775a1693..e1eca14e 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -24,6 +24,8 @@ 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 From 2535ad578946482ae7526288c5c3e756281349fd Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Tue, 20 Apr 2021 11:52:36 +0200 Subject: [PATCH 7/9] Found another place with python setup.py test --- CONTRIBUTING.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5b605ed0..d68e662a 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-*; 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; From c2ebf7665309ad661a8e8d5c19a62bb6dac929af Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Tue, 20 Apr 2021 11:59:00 +0200 Subject: [PATCH 8/9] Update CONTRIBUTING.md Co-authored-by: Erik Tjong Kim Sang --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d68e662a..652577ee 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,7 +31,7 @@ The sections below outline the steps in each case. 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. 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-*; +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; From 332c9bc0a7a4b2c9e2dde315fdd059b523c1380e Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Tue, 20 Apr 2021 12:09:27 +0200 Subject: [PATCH 9/9] Remove alias again --- {{cookiecutter.project_name}}/setup.cfg | 5 ----- 1 file changed, 5 deletions(-) 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 }}