Git Product home page Git Product logo

cookiecutter-pytest-plugin's Introduction

cookiecutter-pytest-plugin

Documentation Status

Minimal Cookiecutter template for authoring pytest plugins that help you to write better programs.

This template requires Cookiecutter 1.4.0 "Shortbread" or higher

Getting Started

Install Cookiecutter and generate a new pytest plugin project:

$ pip install cookiecutter
$ cookiecutter https://github.com/pytest-dev/cookiecutter-pytest-plugin

Cookiecutter prompts you for information regarding your plugin:

full_name [Raphael Pierzina]: Andreas Pelme
email [[email protected]]: [email protected]
github_username [hackebrot]: pelme
plugin_name [foobar]: awesome
module_name [awesome]: awesome
short_description [A simple plugin to use with pytest]:
version [0.1.0]:
pytest_version [2.9.1]:
Select docs_tool:
1 - mkdocs
2 - sphinx
3 - none
Choose from 1, 2, 3 [1]: 1
Select license:
1 - MIT
2 - BSD-3
3 - GNU GPL v3.0+
Choose from 1, 2, 3 [1]: 2
INFO:post_gen_project:Moving files for mkdocs.

There you go - you just created a minimal pytest plugin:

pytest-awesome/
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.rst
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ src
β”‚   └── pytest_awesome
β”‚       β”œβ”€β”€ __init__.py
β”‚       └── plugin.py
β”œβ”€β”€ tests
β”‚   β”œβ”€β”€ conftest.py
β”‚   └── test_awesome.py
└── tox.ini

Features

  • 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 option
  • Comprehensive README.rst file that contains useful information about your plugin
  • Continuous integration configuration for GitHub Actions
  • Optional documentation with either Sphinx or MkDocs
  • Choose from several licenses, such as MIT, BSD-3, Apache v2.0, GNU GPL v3.0+, or MPL v2.0

Requirements to Submit a Plugin

If you plan on submitting your plugin to the pytest-dev organization you need to meet the following requirements:

  • 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.
  • an issue tracker

Please see the official guidelines at Submit a Plugin.

Resources

Please consult the pytest docs for more information on hooks at pytest hook reference.

Contribute

We welcome you to contribute to this project. Please visit the documentation to get started!

Issues

If you encounter any problems, please file an issue along with a detailed description.

Code of Conduct

Everyone interacting in the Cookiecutter pytest Plugin project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the PyPA Code of Conduct.

License

Distributed under the terms of the MIT license, Cookiecutter pytest Plugin is free and open source software.

OSI certified

cookiecutter-pytest-plugin's People

Contributors

abusalimov avatar asottile avatar bluetech avatar cclauss avatar gh-ppolk avatar gitter-badger avatar hackebrot avatar hugovk avatar ktosiek avatar luzfcb avatar m0dm avatar m1troll avatar matrixise avatar nicoddemus avatar obestwalter avatar omarkohl avatar pelme avatar rciorba avatar ronnie-llamado avatar s0undt3ch avatar stranger6667 avatar the-compiler avatar tjsmart avatar xuhdev avatar yashtodi94 avatar yukihiko-shinoda avatar zac-hd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cookiecutter-pytest-plugin's Issues

Tests do not work

After installing and creating the plugin structure, I try to run original tests, that ship with plugin template. But that does not work.

For example, one of the tests cannot find default bar fixture, and I have this error:

Π‘Π½ΠΈΠΌΠΎΠΊ экрана 2020-01-25 Π² 23 33 44

Also, testdir.makeini does not create any params.

I have pytest version 5.3.4 and python 3.8.0.

Custom hooks

  • Define hooks
  • Register them
  • Implement them

This should be a choice in cookiecutter.json.

Expand contributing documentation

Currently the contributing documentation does not include how to run the tests associated with this cookiecutter. I propose:

  • Adding a description to the readme to help people contribute.
  • Adding the contributors code of conduct documentation
    @pytest-dev

Add an AppVeyor initial script

Add a template for an appveyor.yml file similar to .travis.yml.

Note: A lot of projects out there copy/paste a install.ps1 script and use that within the appveyor.yml file, but if you don't need py26 support this is not necessary because AppVeyor VMs come with py27, py32, py33, py34 and py35 pre-installed so it is just a matter of calling tox from one of those python versions.

For example:

install:
  - set PATH=C:\Python35;C:\Python35\Scripts;%PATH%
  - python -m pip install tox

build: false  # Not a C# project

test_script:
  - tox -e py27,py32,py33,py34,py35

Using -f with this template yields wrong results for docs

Due to cookiecutter/cookiecutter#458 repeatedly running the same cookiecutter with -f leads to this behaviour:

(tox) 13:55:53 ob@h2g2 [1] < ~/do/tox-dev >  914 %
rm -rf pytest-foobaz
(tox) 13:56:05 ob@h2g2 [0] < ~/do/tox-dev >  915 %
cookiecutter -f --replay cookiecutter-pytest-plugin
INFO:post_gen_project:Moving files for mkdocs.
INFO:post_gen_project:Removing all temporary license files
INFO:post_gen_project:Removing jinja2 macros
(tox) 13:56:07 ob@h2g2 [0] < ~/do/tox-dev >  916 %
cookiecutter -f --replay cookiecutter-pytest-plugin
INFO:post_gen_project:Moving files for mkdocs.
INFO:post_gen_project:Removing all temporary license files
INFO:post_gen_project:Removing jinja2 macros
(tox) 13:56:09 ob@h2g2 [0] < ~/do/tox-dev >  917 %
cookiecutter -f --replay cookiecutter-pytest-plugin
INFO:post_gen_project:Moving files for mkdocs.
Traceback (most recent call last):
  File "/tmp/tmp1np2t72r.py", line 16, in <module>
    shutil.move('mkdocs', 'docs')
  File "/usr/lib/python3.6/shutil.py", line 542, in move
    raise Error("Destination path '%s' already exists" % real_dst)
shutil.Error: Destination path 'docs/mkdocs' already exists
ERROR: Stopping generation because post_gen_project hook script didn't exit successfully
Hook script failed (exit status: 1)

The first time the project is created and all is fine. The second time around the mkdocs folder is copied into the already existing docs folder therefore doing something wrong but not complaining yet. the third time around it crashes because it tries to write again into the wrong subfolder.

Use src layout

Thank you for the very handy template! Just a curiosity I guess, I created my package, pytest-blah, and there's a source file in the root (pytest_blah.py) along with setup.py etc. When I run python setup.py develop the root containing these files is added to my path, so I can do things like import setup or import pytest_blah directly (I've tried this from outside the root so it's not just a current directory thing).

Have I done something wrong or is that how it's supposed to be? Seems weird to have things like setup.py importable when the package is installed. I ended up making a pytest_blah directory, moving everything from pytest_blah.py into pytest_blah/init.py and putting all the other source files in there and it works as I expect.

EDIT: short example of what I mean: https://gist.github.com/danmur/0489969229281165424b0044f4236b92

.travis.yml doesn't run flake8

Having travis (or appveyor) be able to lint my code and any pull requests as part of a contribution is important, and the current templates do not accounts for a flake8 test env.

Transition from testdir to pytester

According to the API docs, as of pytest 6.2, the use of testdir is discouraged in favor of the new pytester instance ("New code should avoid using testdir in favor of pytester"). This project should consider updating to comply with the new recommendation.

I grepped my local copy of this repo, and I believe it only references the old 'testdir instance in the file "test_{{cookiecutter.module_name}}.py".

I may be able to make this change myself and issue a PR at some point in the near future, when my knowledge of Pytest is a bit more complete. :-)

add `.pre-commit-config` and formatting rules

I just wanted to create a pytest-plugin.

When using the cookiecutter-pytest-plugin I realized that some IHMO essentials are missing.

Before you get a pull request, I'd like to discuss what to add.

  • ruff (similar configuration as pytest itself)
  • pyproject-fmt
  • pyupgrade
  • py-deprecated
  • mypy

We could also extend the .gitignore with the common IDE project files.

  • .idea
  • .project
  • .settings
  • .vscode

Tox virtualenv for Python 3 imports Python 2 libs

Apparently there are problems with the virtualenvs that tox creates for the template. πŸ˜• It is trying to import ConfigParser from Python 2 in a Python 3 environment…that’s messed up.

Add an option "Other" to licenses

Right now there is only three options of license, there should be a new named "other", so the user could type the license that he/she wants

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.