From e039b58c6f4c9dcb9b2e3eb95dfa7c5a9d78e48d Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 18 Jan 2024 23:10:47 +0200 Subject: [PATCH 1/9] Remove `coding: utf-8` directives No longer needed these days. --- hooks/post_gen_project.py | 1 - hooks/pre_gen_project.py | 1 - .../docs_sources/sphinx/conf.py | 2 -- .../pytest_{{cookiecutter.module_name}}.py | 2 -- .../tests/test_{{cookiecutter.module_name}}.py | 3 --- tests/test_create_template.py | 2 -- 6 files changed, 11 deletions(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index a300dd3..e93cf0c 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import logging import os diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index 6f61736..283d67e 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import logging import re diff --git a/pytest-{{cookiecutter.plugin_name}}/docs_sources/sphinx/conf.py b/pytest-{{cookiecutter.plugin_name}}/docs_sources/sphinx/conf.py index c334c03..4cb65f7 100644 --- a/pytest-{{cookiecutter.plugin_name}}/docs_sources/sphinx/conf.py +++ b/pytest-{{cookiecutter.plugin_name}}/docs_sources/sphinx/conf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # pytest-{{cookiecutter.plugin_name}} documentation build configuration file, created by # sphinx-quickstart on Thu Oct 1 00:43:18 2015. # diff --git a/pytest-{{cookiecutter.plugin_name}}/pytest_{{cookiecutter.module_name}}.py b/pytest-{{cookiecutter.plugin_name}}/pytest_{{cookiecutter.module_name}}.py index 4b95f95..48bce20 100644 --- a/pytest-{{cookiecutter.plugin_name}}/pytest_{{cookiecutter.module_name}}.py +++ b/pytest-{{cookiecutter.plugin_name}}/pytest_{{cookiecutter.module_name}}.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import pytest diff --git a/pytest-{{cookiecutter.plugin_name}}/tests/test_{{cookiecutter.module_name}}.py b/pytest-{{cookiecutter.plugin_name}}/tests/test_{{cookiecutter.module_name}}.py index 6fcfb4b..53a95d5 100644 --- a/pytest-{{cookiecutter.plugin_name}}/tests/test_{{cookiecutter.module_name}}.py +++ b/pytest-{{cookiecutter.plugin_name}}/tests/test_{{cookiecutter.module_name}}.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - def test_bar_fixture(testdir): """Make sure that pytest accepts our fixture.""" diff --git a/tests/test_create_template.py b/tests/test_create_template.py index cce4f46..f3fa1fa 100644 --- a/tests/test_create_template.py +++ b/tests/test_create_template.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ test_create_template -------------------- From b397d63eed2975f9ab93d4687f4b8b1ddf986677 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 18 Jan 2024 23:21:29 +0200 Subject: [PATCH 2/9] tests: fix `pytest.fail` call --- tests/test_create_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_create_template.py b/tests/test_create_template.py index f3fa1fa..c279824 100644 --- a/tests/test_create_template.py +++ b/tests/test_create_template.py @@ -19,7 +19,7 @@ def run_tox(plugin): '-e', 'py' ]) except subprocess.CalledProcessError as e: - pytest.fail(e) + pytest.fail(str(e)) def test_run_cookiecutter_and_plugin_tests(cookies): From 69dfb7750db86f145633f6d4ec7c92f427c71622 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 18 Jan 2024 23:38:54 +0200 Subject: [PATCH 3/9] tests: fix tox call --- tests/test_create_template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_create_template.py b/tests/test_create_template.py index c279824..fb77ebf 100644 --- a/tests/test_create_template.py +++ b/tests/test_create_template.py @@ -14,9 +14,9 @@ def run_tox(plugin): try: subprocess.check_call([ 'tox', - plugin, + '--workdir', plugin, '-c', os.path.join(plugin, 'tox.ini'), - '-e', 'py' + '-e', 'py', ]) except subprocess.CalledProcessError as e: pytest.fail(str(e)) From 237a03f08cf26fbed9fa1c28b342b502a79ae6df Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 18 Jan 2024 22:59:41 +0200 Subject: [PATCH 4/9] ci: update github actions versions --- .github/workflows/run-checks.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-checks.yml b/.github/workflows/run-checks.yml index 298d118..eb9da16 100644 --- a/.github/workflows/run-checks.yml +++ b/.github/workflows/run-checks.yml @@ -26,8 +26,8 @@ jobs: python: "3.8" steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} - name: Install tox From 7afb2ffd50681a63eff16eb5bf61a9f684f29cbb Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 18 Jan 2024 22:57:57 +0200 Subject: [PATCH 5/9] Modernize the supported Python versions --- .github/workflows/run-checks.yml | 12 ++---------- .../appveyor.yml | 19 +++++++++++-------- pytest-{{cookiecutter.plugin_name}}/setup.py | 7 ++++--- pytest-{{cookiecutter.plugin_name}}/tox.ini | 2 +- tox.ini | 2 +- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.github/workflows/run-checks.yml b/.github/workflows/run-checks.yml index eb9da16..79034ac 100644 --- a/.github/workflows/run-checks.yml +++ b/.github/workflows/run-checks.yml @@ -17,13 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - include: - - environment: "py36" - python: "3.6" - - environment: "py37" - python: "3.7" - - environment: "py38" - python: "3.8" + python: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 @@ -31,8 +25,6 @@ jobs: with: python-version: ${{ matrix.python }} - name: Install tox - run: | - python -m pip install --upgrade pip - python -m pip install tox + run: pip install tox - name: Run tox run: tox -e py diff --git a/pytest-{{cookiecutter.plugin_name}}/appveyor.yml b/pytest-{{cookiecutter.plugin_name}}/appveyor.yml index 61bdd15..5015b33 100644 --- a/pytest-{{cookiecutter.plugin_name}}/appveyor.yml +++ b/pytest-{{cookiecutter.plugin_name}}/appveyor.yml @@ -3,17 +3,20 @@ environment: matrix: - - PYTHON: "C:\\Python35" - TOX_ENV: "py35" + - PYTHON: "C:\\Python38" + TOX_ENV: "py38" - - PYTHON: "C:\\Python36" - TOX_ENV: "py36" + - PYTHON: "C:\\Python39" + TOX_ENV: "py39" - - PYTHON: "C:\\Python37" - TOX_ENV: "py37" + - PYTHON: "C:\\Python310" + TOX_ENV: "py310" - - PYTHON: "C:\\Python38" - TOX_ENV: "py38" + - PYTHON: "C:\\Python311" + TOX_ENV: "py311" + + - PYTHON: "C:\\Python312" + TOX_ENV: "py312" init: - "%PYTHON%/python -V" diff --git a/pytest-{{cookiecutter.plugin_name}}/setup.py b/pytest-{{cookiecutter.plugin_name}}/setup.py index efa9ee6..0ff48ee 100644 --- a/pytest-{{cookiecutter.plugin_name}}/setup.py +++ b/pytest-{{cookiecutter.plugin_name}}/setup.py @@ -32,10 +32,11 @@ def read(fname): 'Topic :: Software Development :: Testing', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', diff --git a/pytest-{{cookiecutter.plugin_name}}/tox.ini b/pytest-{{cookiecutter.plugin_name}}/tox.ini index e99d0b0..a334195 100644 --- a/pytest-{{cookiecutter.plugin_name}}/tox.ini +++ b/pytest-{{cookiecutter.plugin_name}}/tox.ini @@ -1,6 +1,6 @@ # For more information about tox, see https://tox.readthedocs.io/en/latest/ [tox] -envlist = py35,py36,py37,py38,pypy3,flake8 +envlist = py38,py39,py310,py311,py312,pypy3,flake8 [testenv] deps = pytest>=3.0 diff --git a/tox.ini b/tox.ini index 2021d1f..c63d876 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] recreate = true skipsdist = true -envlist = py35, py36, py37, py38, pypy3 +envlist = py38, py39, py310, py311, py312, pypy3 [testenv] deps = pytest From 50ef292f2fca50e613da3831c46afcb3ba9b24cb Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 18 Jan 2024 23:01:43 +0200 Subject: [PATCH 6/9] Modernize required pytest version 3.0 -> 6.2 --- cookiecutter.json | 2 +- pytest-{{cookiecutter.plugin_name}}/tox.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 8c19c77..61cbb8e 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -6,7 +6,7 @@ "module_name": "{{ cookiecutter.plugin_name|lower|replace('-', '_') }}", "short_description": "A simple plugin to use with pytest", "version": "0.1.0", - "pytest_version": "3.5.0", + "pytest_version": "6.2.0", "docs_tool": [ "mkdocs", "sphinx", diff --git a/pytest-{{cookiecutter.plugin_name}}/tox.ini b/pytest-{{cookiecutter.plugin_name}}/tox.ini index a334195..6ee7df2 100644 --- a/pytest-{{cookiecutter.plugin_name}}/tox.ini +++ b/pytest-{{cookiecutter.plugin_name}}/tox.ini @@ -3,7 +3,7 @@ envlist = py38,py39,py310,py311,py312,pypy3,flake8 [testenv] -deps = pytest>=3.0 +deps = pytest>={{cookiecutter.pytest_version}} commands = pytest {posargs:tests} [testenv:flake8] From 02ebf296c2b2f957b8f532c9409a7fa0d7f7c4c5 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 18 Jan 2024 22:49:42 +0200 Subject: [PATCH 7/9] Convert setup.py -> pyproject.toml, flat layout -> src layout pyproject.toml is the more modern way to do it, and we can remove all setuptools dependence except for choosing it as the build backend. src layout is less error prone than flat layout, given that tox is used. Fix #38, #30, #24 --- README.md | 24 ++++---- docs/user-guide/publish-plugin.md | 11 ++-- docs/user-guide/quickstart.md | 11 ++-- .../MANIFEST.in | 5 -- .../appveyor.yml | 47 ++++---------- .../pyproject.toml | 53 ++++++++++++++++ pytest-{{cookiecutter.plugin_name}}/setup.py | 61 ------------------- .../__init__.py | 0 .../plugin.py} | 0 pytest-{{cookiecutter.plugin_name}}/tox.ini | 2 +- tests/test_create_template.py | 3 +- 11 files changed, 90 insertions(+), 127 deletions(-) delete mode 100644 pytest-{{cookiecutter.plugin_name}}/MANIFEST.in create mode 100644 pytest-{{cookiecutter.plugin_name}}/pyproject.toml delete mode 100644 pytest-{{cookiecutter.plugin_name}}/setup.py create mode 100644 pytest-{{cookiecutter.plugin_name}}/src/pytest_{{cookiecutter.module_name}}/__init__.py rename pytest-{{cookiecutter.plugin_name}}/{pytest_{{cookiecutter.module_name}}.py => src/pytest_{{cookiecutter.module_name}}/plugin.py} (100%) diff --git a/README.md b/README.md index d7f536c..4b17ce5 100644 --- a/README.md +++ b/README.md @@ -47,21 +47,21 @@ There you go - you just created a minimal pytest plugin: pytest-awesome/ ├── LICENSE ├── README.rst -├── docs -│   └── index.md -├── mkdocs.yml -├── pytest_awesome.py -├── setup.py +├── pyproject.toml +├── src +│ └── pytest_awesome +│ ├── __init__.py +│ └── plugin.py ├── tests -│   ├── conftest.py -│   └── test_awesome.py +│ ├── conftest.py +│ └── test_awesome.py └── tox.ini ``` ## Features -- Installable [PyPI] package featuring a `setup.py`. +- Installable [PyPI] package featuring a `pyproject.toml`. - Test suite running [tox] and [pytest] that makes sure your plugin is working as expected - Working example code for a fixture, a cli option, as well as a pytest.ini @@ -78,15 +78,13 @@ pytest-awesome/ If you plan on submitting your plugin to the [pytest-dev organization] you need to meet the following requirements: -- PyPI presence with a setup.py that contains a license, pytest- +- PyPI presence with a pyproject.toml that contains a license, pytest- prefixed, version number, authors, short and long description. - a tox.ini for running tests using tox. - a README describing how to use the plugin and on which platforms it runs. -- a LICENSE file or equivalent containing the licensing information, - with matching info in setup.py. -- an issue tracker unless you rather want to use the core pytest - issue tracker. +- a LICENSE file or equivalent containing the licensing information. +- an issue tracker Please see the official guidelines at [Submit a Plugin]. diff --git a/docs/user-guide/publish-plugin.md b/docs/user-guide/publish-plugin.md index 8f2cc88..7900805 100644 --- a/docs/user-guide/publish-plugin.md +++ b/docs/user-guide/publish-plugin.md @@ -6,8 +6,7 @@ Essentially pytest plugins are not different from any other Python Package, so you may want to create a distribution and submit it to the Python Package Index ([PyPI]). -By doing so, enables your users to easily install via ``easy-install`` or -``pip``. +By doing so, enables your users to easily install via ``pip``. ## Python Package Index @@ -24,15 +23,13 @@ Please see the official [Python Packaging User Guide] for detailed information. If you plan on submitting your plugin to the [pytest-dev organization] you need to meet the following requirements: -- PyPI presence with a setup.py that contains a license, pytest- +- PyPI presence with a pyproject.toml that contains a license, pytest- prefixed, version number, authors, short and long description. - a tox.ini for running tests using tox. - a README describing how to use the plugin and on which platforms it runs. -- a LICENSE file or equivalent containing the licensing information, - with matching info in setup.py. -- an issue tracker unless you rather want to use the core pytest - issue tracker. +- a LICENSE file or equivalent containing the licensing information. +- an issue tracker. Please see the official guidelines at [Submit a Plugin]. diff --git a/docs/user-guide/quickstart.md b/docs/user-guide/quickstart.md index 6848698..197fd96 100644 --- a/docs/user-guide/quickstart.md +++ b/docs/user-guide/quickstart.md @@ -53,11 +53,14 @@ Once you answered to the questions, Cookiecutter renders the the project: pytest-awesome/ ├── LICENSE ├── README.rst -├── pytest_awesome.py -├── setup.py +├── pyproject.toml +├── src +│ └── pytest_awesome +│ ├── __init__.py +│ └── plugin.py ├── tests -│   ├── conftest.py -│   └── test_awesome.py +│ ├── conftest.py +│ └── test_awesome.py └── tox.ini ``` diff --git a/pytest-{{cookiecutter.plugin_name}}/MANIFEST.in b/pytest-{{cookiecutter.plugin_name}}/MANIFEST.in deleted file mode 100644 index 1ade348..0000000 --- a/pytest-{{cookiecutter.plugin_name}}/MANIFEST.in +++ /dev/null @@ -1,5 +0,0 @@ -include LICENSE -include README.rst - -recursive-exclude * __pycache__ -recursive-exclude * *.py[co] diff --git a/pytest-{{cookiecutter.plugin_name}}/appveyor.yml b/pytest-{{cookiecutter.plugin_name}}/appveyor.yml index 5015b33..f22b384 100644 --- a/pytest-{{cookiecutter.plugin_name}}/appveyor.yml +++ b/pytest-{{cookiecutter.plugin_name}}/appveyor.yml @@ -1,43 +1,20 @@ -# What Python version is installed where: -# https://www.appveyor.com/docs/build-environment/#python +# https://www.appveyor.com/docs/lang/python/ +--- +image: + - Visual Studio 2019 environment: matrix: - - PYTHON: "C:\\Python38" - TOX_ENV: "py38" + - TOXENV: "py38" + - TOXENV: "py39" + - TOXENV: "py310" + - TOXENV: "py311" + - TOXENV: "py312" - - PYTHON: "C:\\Python39" - TOX_ENV: "py39" - - - PYTHON: "C:\\Python310" - TOX_ENV: "py310" - - - PYTHON: "C:\\Python311" - TOX_ENV: "py311" - - - PYTHON: "C:\\Python312" - TOX_ENV: "py312" - -init: - - "%PYTHON%/python -V" - - "%PYTHON%/python -c \"import struct;print( 8 * struct.calcsize(\'P\'))\"" +build: false install: - - "%PYTHON%/Scripts/easy_install -U pip" - - "%PYTHON%/Scripts/pip install tox" - - "%PYTHON%/Scripts/pip install wheel" - -build: false # Not a C# project, build stuff at the test step instead. + - py -m pip install tox test_script: - - "%PYTHON%/Scripts/tox -e %TOX_ENV%" - -after_test: - - "%PYTHON%/python setup.py bdist_wheel" - - ps: "ls dist" - -artifacts: - - path: dist\* - -#on_success: -# - TODO: upload the content of dist/*.whl to a public wheelhouse + - py -m tox diff --git a/pytest-{{cookiecutter.plugin_name}}/pyproject.toml b/pytest-{{cookiecutter.plugin_name}}/pyproject.toml new file mode 100644 index 0000000..c48c057 --- /dev/null +++ b/pytest-{{cookiecutter.plugin_name}}/pyproject.toml @@ -0,0 +1,53 @@ +[build-system] +requires = [ + "setuptools>=61.0.0", +] +build-backend = "setuptools.build_meta" + +[project] +name = "pytest-{{cookiecutter.plugin_name}}" +description = "{{cookiecutter.short_description}}" +version = "{{cookiecutter.version}}" +readme = "README.rst" +requires-python = ">=3.8" +authors = [ + { name = "{{cookiecutter.full_name}}", email = "{{cookiecutter.email}}" }, +] +maintainers = [ + { name = "{{cookiecutter.full_name}}", email = "{{cookiecutter.email}}" }, +] +license = {file = "LICENSE"} +classifiers = [ + "Framework :: Pytest", + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Topic :: Software Development :: Testing", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + {% if cookiecutter.license == "MIT" -%} + "License :: OSI Approved :: MIT License", + {%- elif cookiecutter.license == "BSD-3" -%} + "License :: OSI Approved :: BSD License", + {%- elif cookiecutter.license == "GNU GPL v3.0+" -%} + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", + {%- elif cookiecutter.license == "Apache Software License 2.0" -%} + "License :: OSI Approved :: Apache Software License", + {%- elif cookiecutter.license == "Mozilla Public License 2.0" -%} + "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", + {%- endif %} +] +dependencies = [ + "pytest>={{cookiecutter.pytest_version}}", +] +[project.urls] +Repository = "https://github.com/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}" +[project.entry-points.pytest11] +django = "pytest_{{cookiecutter.module_name}}.plugin" diff --git a/pytest-{{cookiecutter.plugin_name}}/setup.py b/pytest-{{cookiecutter.plugin_name}}/setup.py deleted file mode 100644 index 0ff48ee..0000000 --- a/pytest-{{cookiecutter.plugin_name}}/setup.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import os -import codecs -from setuptools import setup - - -def read(fname): - file_path = os.path.join(os.path.dirname(__file__), fname) - return codecs.open(file_path, encoding='utf-8').read() - - -setup( - name='pytest-{{cookiecutter.plugin_name}}', - version='{{cookiecutter.version}}', - author='{{cookiecutter.full_name}}', - author_email='{{cookiecutter.email}}', - maintainer='{{cookiecutter.full_name}}', - maintainer_email='{{cookiecutter.email}}', - license='{{cookiecutter.license}}', - url='https://github.com/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}', - description='{{cookiecutter.short_description}}', - long_description=read('README.rst'), - py_modules=['pytest_{{cookiecutter.module_name}}'], - python_requires='>=3.5', - install_requires=['pytest>={{cookiecutter.pytest_version}}'], - classifiers=[ - 'Development Status :: 4 - Beta', - 'Framework :: Pytest', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Testing', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - 'Operating System :: OS Independent', - {% if cookiecutter.license == "MIT" -%} - 'License :: OSI Approved :: MIT License', - {%- elif cookiecutter.license == "BSD-3" -%} - 'License :: OSI Approved :: BSD License', - {%- elif cookiecutter.license == "GNU GPL v3.0+" -%} - 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', - {%- elif cookiecutter.license == "Apache Software License 2.0" -%} - 'License :: OSI Approved :: Apache Software License', - {%- elif cookiecutter.license == "Mozilla Public License 2.0" -%} - 'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)', - {%- endif %} - ], - entry_points={ - 'pytest11': [ - '{{cookiecutter.plugin_name}} = pytest_{{cookiecutter.module_name}}', - ], - }, -) diff --git a/pytest-{{cookiecutter.plugin_name}}/src/pytest_{{cookiecutter.module_name}}/__init__.py b/pytest-{{cookiecutter.plugin_name}}/src/pytest_{{cookiecutter.module_name}}/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pytest-{{cookiecutter.plugin_name}}/pytest_{{cookiecutter.module_name}}.py b/pytest-{{cookiecutter.plugin_name}}/src/pytest_{{cookiecutter.module_name}}/plugin.py similarity index 100% rename from pytest-{{cookiecutter.plugin_name}}/pytest_{{cookiecutter.module_name}}.py rename to pytest-{{cookiecutter.plugin_name}}/src/pytest_{{cookiecutter.module_name}}/plugin.py diff --git a/pytest-{{cookiecutter.plugin_name}}/tox.ini b/pytest-{{cookiecutter.plugin_name}}/tox.ini index 6ee7df2..19d93be 100644 --- a/pytest-{{cookiecutter.plugin_name}}/tox.ini +++ b/pytest-{{cookiecutter.plugin_name}}/tox.ini @@ -9,4 +9,4 @@ commands = pytest {posargs:tests} [testenv:flake8] skip_install = true deps = flake8 -commands = flake8 pytest_{{cookiecutter.module_name}}.py setup.py tests +commands = flake8 src tests diff --git a/tests/test_create_template.py b/tests/test_create_template.py index fb77ebf..6c0ef34 100644 --- a/tests/test_create_template.py +++ b/tests/test_create_template.py @@ -30,7 +30,8 @@ def test_run_cookiecutter_and_plugin_tests(cookies): assert result.exception is None assert result.project.basename == 'pytest-foo-bar' assert result.project.isdir() - assert result.project.join('pytest_foo_bar.py').isfile() + assert result.project.join('src', 'pytest_foo_bar', '__init__.py').isfile() + assert result.project.join('src', 'pytest_foo_bar', 'plugin.py').isfile() assert result.project.join('tests', 'test_foo_bar.py').isfile() run_tox(str(result.project)) From a9ff901a0ea1b89b46e87d1466daaff563fec783 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 18 Jan 2024 23:13:15 +0200 Subject: [PATCH 8/9] Change tests from `testdir` to `pytester` `testdir` is soft-deprecated in pytest, `pytester` is the replacement. Fix #51 --- .../tests/test_{{cookiecutter.module_name}}.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pytest-{{cookiecutter.plugin_name}}/tests/test_{{cookiecutter.module_name}}.py b/pytest-{{cookiecutter.plugin_name}}/tests/test_{{cookiecutter.module_name}}.py index 53a95d5..1600368 100644 --- a/pytest-{{cookiecutter.plugin_name}}/tests/test_{{cookiecutter.module_name}}.py +++ b/pytest-{{cookiecutter.plugin_name}}/tests/test_{{cookiecutter.module_name}}.py @@ -1,14 +1,14 @@ -def test_bar_fixture(testdir): +def test_bar_fixture(pytester): """Make sure that pytest accepts our fixture.""" # create a temporary pytest test module - testdir.makepyfile(""" + pytester.makepyfile(""" def test_sth(bar): assert bar == "europython2015" """) # run pytest with the following cmd args - result = testdir.runpytest( + result = pytester.runpytest( '--foo=europython2015', '-v' ) @@ -22,8 +22,8 @@ def test_sth(bar): assert result.ret == 0 -def test_help_message(testdir): - result = testdir.runpytest( +def test_help_message(pytester): + result = pytester.runpytest( '--help', ) # fnmatch_lines does an assertion internally @@ -33,13 +33,13 @@ def test_help_message(testdir): ]) -def test_hello_ini_setting(testdir): - testdir.makeini(""" +def test_hello_ini_setting(pytester): + pytester.makeini(""" [pytest] HELLO = world """) - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest @pytest.fixture @@ -50,7 +50,7 @@ def test_hello_world(hello): assert hello == 'world' """) - result = testdir.runpytest('-v') + result = pytester.runpytest('-v') # fnmatch_lines does an assertion internally result.stdout.fnmatch_lines([ From b4bc84ca6d8fe20e6bad7facaffc1700bfdfbefa Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 18 Jan 2024 23:16:28 +0200 Subject: [PATCH 9/9] tests: replace deprecated cookies `result.project` -> `result.project_path` --- tests/test_create_template.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/test_create_template.py b/tests/test_create_template.py index 6c0ef34..55fb6a1 100644 --- a/tests/test_create_template.py +++ b/tests/test_create_template.py @@ -1,9 +1,3 @@ -""" -test_create_template --------------------- -""" - - import os import pytest import subprocess @@ -28,10 +22,10 @@ def test_run_cookiecutter_and_plugin_tests(cookies): assert result.exit_code == 0 assert result.exception is None - assert result.project.basename == 'pytest-foo-bar' - assert result.project.isdir() - assert result.project.join('src', 'pytest_foo_bar', '__init__.py').isfile() - assert result.project.join('src', 'pytest_foo_bar', 'plugin.py').isfile() - assert result.project.join('tests', 'test_foo_bar.py').isfile() + assert result.project_path.name == 'pytest-foo-bar' + assert result.project_path.is_dir() + assert result.project_path.joinpath('src', 'pytest_foo_bar', '__init__.py').is_file() + assert result.project_path.joinpath('src', 'pytest_foo_bar', 'plugin.py').is_file() + assert result.project_path.joinpath('tests', 'test_foo_bar.py').is_file() - run_tox(str(result.project)) + run_tox(str(result.project_path))