2015-02-27 18:54:17 +08:00
============================
Contribution getting started
============================
2014-01-22 18:37:02 +08:00
Contributions are highly welcomed and appreciated. Every little help counts,
so do not hesitate!
2015-02-27 18:54:17 +08:00
.. contents :: Contribution links
:depth: 2
2014-01-23 17:51:45 +08:00
2015-02-27 18:54:17 +08:00
2016-02-19 05:13:29 +08:00
.. _submitfeedback:
2015-02-27 18:54:17 +08:00
2016-02-19 05:13:29 +08:00
Feature requests and feedback
-----------------------------
2015-02-27 18:54:17 +08:00
2016-02-19 05:13:29 +08:00
Do you like pytest? Share some love on Twitter or in your blog posts!
2015-03-19 19:53:32 +08:00
2016-02-19 05:13:29 +08:00
We'd also like to hear about your propositions and suggestions. Feel free to
2016-02-20 04:23:38 +08:00
`submit them as issues <https://github.com/pytest-dev/pytest/issues> `_ and:
2015-02-27 18:54:17 +08:00
2016-02-19 05:13:29 +08:00
* Explain in detail how they should work.
* Keep the scope as narrow as possible. This will make it easier to implement.
2015-02-27 18:54:17 +08:00
.. _reportbugs:
2014-01-22 18:37:02 +08:00
2014-01-23 18:38:05 +08:00
Report bugs
-----------
2016-02-19 05:13:29 +08:00
Report bugs for pytest in the `issue tracker <https://github.com/pytest-dev/pytest/issues> `_ .
2014-01-23 18:38:05 +08:00
If you are reporting a bug, please include:
* Your operating system name and version.
* Any details about your local setup that might be helpful in troubleshooting,
2017-07-26 00:27:26 +08:00
specifically the Python interpreter version, installed libraries, and pytest
version.
2014-01-23 18:38:05 +08:00
* Detailed steps to reproduce the bug.
2017-07-26 00:27:26 +08:00
If you can write a demonstration test that currently fails but should pass
(xfail), that is a very useful commit to make as well, even if you cannot
fix the bug itself.
2015-07-26 18:19:39 +08:00
2014-01-22 18:37:02 +08:00
2015-02-27 18:54:17 +08:00
.. _fixbugs:
2014-01-22 18:37:02 +08:00
Fix bugs
--------
2018-04-13 18:33:58 +08:00
Look through the `GitHub issues for bugs <https://github.com/pytest-dev/pytest/labels/type:%20bug> `_ .
2014-01-22 18:37:02 +08:00
2014-01-22 19:19:33 +08:00
:ref: `Talk <contact>` to developers to find out how you can fix specific bugs.
2014-01-22 18:37:02 +08:00
2015-07-26 18:19:39 +08:00
Don't forget to check the issue trackers of your favourite plugins, too!
2015-02-27 18:54:17 +08:00
.. _writeplugins:
2014-01-22 18:37:02 +08:00
Implement features
------------------
2018-04-13 18:33:58 +08:00
Look through the `GitHub issues for enhancements <https://github.com/pytest-dev/pytest/labels/type:%20enhancement> `_ .
2014-01-22 18:37:02 +08:00
2014-01-22 19:19:33 +08:00
:ref: `Talk <contact>` to developers to find out how you can implement specific
2014-01-22 18:37:02 +08:00
features.
Write documentation
-------------------
2016-06-22 15:13:01 +08:00
Pytest could always use more documentation. What exactly is needed?
2014-01-22 18:37:02 +08:00
* More complementary documentation. Have you perhaps found something unclear?
2015-07-26 18:19:39 +08:00
* Documentation translations. We currently have only English.
2015-10-24 17:21:22 +08:00
* Docstrings. There can never be too many of them.
2014-01-22 18:37:02 +08:00
* Blog posts, articles and such -- they're all very appreciated.
2016-06-22 15:13:01 +08:00
You can also edit documentation files directly in the GitHub web interface,
without using a local copy. This can be convenient for small fixes.
2015-07-26 18:19:39 +08:00
2016-11-27 01:57:51 +08:00
.. note ::
Build the documentation locally with the following command:
.. code :: bash
$ tox -e docs
The built documentation should be available in the `` doc/en/_build/ `` .
Where 'en' refers to the documentation language.
2016-02-19 05:13:29 +08:00
.. _submitplugin:
Submitting Plugins to pytest-dev
--------------------------------
Pytest development of the core, some plugins and support code happens
in repositories living under the `` pytest-dev `` organisations:
- `pytest-dev on GitHub <https://github.com/pytest-dev> `_
- `pytest-dev on Bitbucket <https://bitbucket.org/pytest-dev> `_
All pytest-dev Contributors team members have write access to all contained
2016-06-22 15:13:01 +08:00
repositories. Pytest core and plugins are generally developed
2016-02-19 05:13:29 +08:00
using `pull requests`_ to respective repositories.
The objectives of the `` pytest-dev `` organisation are:
* Having a central location for popular pytest plugins
2016-06-22 15:13:01 +08:00
* Sharing some of the maintenance responsibility (in case a maintainer no
longer wishes to maintain a plugin)
2016-02-19 05:13:29 +08:00
You can submit your plugin by subscribing to the `pytest-dev mail list
<https://mail.python.org/mailman/listinfo/pytest-dev> `_ and writing a
mail pointing to your existing pytest plugin repository which must have
the following:
- PyPI presence with a `` setup.py `` that contains a license, `` pytest- ``
2016-02-20 04:23:38 +08:00
prefixed name, version number, authors, short and long description.
2016-02-19 05:13:29 +08:00
2017-09-19 22:57:16 +08:00
- a `` tox.ini `` for running tests using `tox <https://tox.readthedocs.io> `_ .
2016-02-19 05:13:29 +08:00
- a `` README.txt `` describing how to use the plugin and on which
platforms it runs.
- a `` LICENSE.txt `` file or equivalent containing the licensing
information, with matching info in `` setup.py `` .
2016-02-20 04:23:38 +08:00
- an issue tracker for bug reports and enhancement requests.
2016-02-19 05:13:29 +08:00
2016-07-01 04:25:09 +08:00
- a `changelog <http://keepachangelog.com/> `_
2016-02-19 05:13:29 +08:00
If no contributor strongly objects and two agree, the repository can then be
transferred to the `` pytest-dev `` organisation.
Here's a rundown of how a repository transfer usually proceeds
2016-02-20 04:23:38 +08:00
(using a repository named `` joedoe/pytest-xyz `` as example):
2016-02-19 05:13:29 +08:00
2016-06-21 15:40:22 +08:00
* `` joedoe `` transfers repository ownership to `` pytest-dev `` administrator `` calvin `` .
* `` calvin `` creates `` pytest-xyz-admin `` and `` pytest-xyz-developers `` teams, inviting `` joedoe `` to both as **maintainer** .
* `` calvin `` transfers repository to `` pytest-dev `` and configures team access:
2018-05-18 16:19:46 +08:00
2016-06-21 15:40:22 +08:00
- `` pytest-xyz-admin `` **admin** access;
- `` pytest-xyz-developers `` **write** access;
2016-02-19 05:13:29 +08:00
The `` pytest-dev/Contributors `` team has write access to all projects, and
every project administrator is in it. We recommend that each plugin has at least three
people who have the right to release to PyPI.
2016-06-21 15:40:22 +08:00
Repository owners can rest assured that no `` pytest-dev `` administrator will ever make
2016-02-20 04:23:38 +08:00
releases of your repository or take ownership in any way, except in rare cases
where someone becomes unresponsive after months of contact attempts.
As stated, the objective is to share maintenance and avoid "plugin-abandon".
2016-02-19 05:13:29 +08:00
2015-02-27 18:54:17 +08:00
.. _`pull requests`:
2015-02-27 23:42:03 +08:00
.. _pull-requests:
2014-01-25 02:21:21 +08:00
2017-07-23 02:58:12 +08:00
Preparing Pull Requests
-----------------------
Short version
~~~~~~~~~~~~~
2018-06-12 07:46:41 +08:00
#. Fork the repository.
#. Enable and install `pre-commit <https://pre-commit.com> `_ to ensure style-guides and code checks are followed.
#. Target `` master `` for bugfixes and doc changes.
2017-07-23 02:58:12 +08:00
#. Target `` features `` for new features or functionality changes.
2018-06-12 07:46:41 +08:00
#. Follow **PEP-8** for naming and `black <https://github.com/ambv/black> `_ for formatting.
2017-07-23 02:58:12 +08:00
#. Tests are run using `` tox `` ::
2018-11-12 04:45:34 +08:00
tox -e linting,py27,py37
2017-07-23 02:58:12 +08:00
2017-07-26 00:27:26 +08:00
The test environments above are usually enough to cover most cases locally.
2017-07-23 02:58:12 +08:00
2017-07-26 00:27:26 +08:00
#. Write a `` changelog `` entry: `` changelog/2574.bugfix `` , use issue id number
and one of `` bugfix `` , `` removal `` , `` feature `` , `` vendor `` , `` doc `` or
`` trivial `` for the issue type.
2017-10-24 04:46:14 +08:00
#. Unless your change is a trivial or a documentation fix (e.g., a typo or reword of a small section) please
2018-06-12 07:46:41 +08:00
add yourself to the `` AUTHORS `` file, in alphabetical order.
2017-07-23 02:58:12 +08:00
Long version
~~~~~~~~~~~~
2014-01-22 18:37:02 +08:00
2017-07-26 00:27:26 +08:00
What is a "pull request"? It informs the project's core developers about the
2017-07-23 02:58:12 +08:00
changes you want to review and merge. Pull requests are stored on
`GitHub servers <https://github.com/pytest-dev/pytest/pulls> `_ .
Once you send a pull request, we can discuss its potential modifications and
2017-07-26 00:27:26 +08:00
even add more commits to it later on. There's an excellent tutorial on how Pull
Requests work in the
2017-07-23 02:58:12 +08:00
`GitHub Help Center <https://help.github.com/articles/using-pull-requests/> `_ .
Here is a simple overview, with pytest-specific bits:
2014-01-22 19:19:33 +08:00
2015-03-03 03:48:09 +08:00
#. Fork the
2015-06-16 05:54:44 +08:00
`pytest GitHub repository <https://github.com/pytest-dev/pytest> `__ . It's
2014-01-25 02:37:44 +08:00
fine to use `` pytest `` as your fork repository name because it will live
under your user.
2014-01-23 18:38:05 +08:00
2015-06-16 05:54:44 +08:00
#. Clone your fork locally using `git <https://git-scm.com/> `_ and create a branch::
2014-01-22 18:37:02 +08:00
2015-06-16 05:54:44 +08:00
$ git clone git@github.com:YOUR_GITHUB_USERNAME/pytest.git
2014-01-23 18:38:05 +08:00
$ cd pytest
2015-09-22 16:21:01 +08:00
# now, to fix a bug create your own branch off "master":
2018-05-18 16:19:46 +08:00
2015-09-22 21:54:37 +08:00
$ git checkout -b your-bugfix-branch-name master
2015-09-22 16:21:01 +08:00
# or to instead add a feature create your own branch off "features":
2018-05-18 16:19:46 +08:00
2015-09-22 21:54:37 +08:00
$ git checkout -b your-feature-branch-name features
2015-09-22 16:21:01 +08:00
2018-05-18 16:19:46 +08:00
Given we have "major.minor.micro" version numbers, bugfixes will usually
be released in micro releases whereas features will be released in
2015-09-22 16:21:01 +08:00
minor releases and incompatible changes in major releases.
2014-01-25 02:37:44 +08:00
2015-06-16 05:54:44 +08:00
If you need some help with Git, follow this quick start
guide: https://git.wiki.kernel.org/index.php/QuickStart
2014-01-22 18:37:02 +08:00
2018-06-12 07:46:41 +08:00
#. Install `pre-commit <https://pre-commit.com> `_ and its hook on the pytest repo::
2018-05-18 15:37:24 +08:00
2018-06-12 07:46:41 +08:00
$ pip install --user pre-commit
$ pre-commit install
2018-05-18 15:37:24 +08:00
2018-06-12 07:46:41 +08:00
Afterwards `` pre-commit `` will run whenever you commit.
2018-05-18 15:37:24 +08:00
2018-06-12 07:46:41 +08:00
https://pre-commit.com/ is a framework for managing and maintaining multi-language pre-commit hooks
to ensure code-style and code formatting is consistent.
2018-05-18 15:37:24 +08:00
2015-09-21 17:49:35 +08:00
#. Install tox
Tox is used to run all the tests and will automatically setup virtualenvs
to run the tests in.
2015-03-03 03:48:09 +08:00
(will implicitly use http://www.virtualenv.org/en/latest/)::
2014-01-22 18:37:02 +08:00
2015-09-21 17:49:35 +08:00
$ pip install tox
2014-01-22 18:37:02 +08:00
2015-09-21 17:49:35 +08:00
#. Run all the tests
2014-01-22 18:37:02 +08:00
2018-11-12 04:45:34 +08:00
You need to have Python 2.7 and 3.7 available in your system. Now
2015-03-03 03:48:09 +08:00
running tests is as simple as issuing this command::
2014-01-22 18:37:02 +08:00
2018-11-12 04:45:34 +08:00
$ tox -e linting,py27,py37
2014-01-22 18:37:02 +08:00
2018-11-12 04:45:34 +08:00
This command will run tests via the "tox" tool against Python 2.7 and 3.7
2017-07-23 02:58:12 +08:00
and also perform "lint" coding-style checks.
2017-07-21 06:14:54 +08:00
2018-06-12 07:46:41 +08:00
#. You can now edit your local working copy and run the tests again as necessary. Please follow PEP-8 for naming.
2015-09-21 17:49:35 +08:00
2017-07-23 02:58:12 +08:00
You can pass different options to `` tox `` . For example, to run tests on Python 2.7 and pass options to pytest
(e.g. enter pdb on failure) to pytest you can do::
2014-01-22 18:37:02 +08:00
2016-11-10 06:42:28 +08:00
$ tox -e py27 -- --pdb
2014-01-22 18:37:02 +08:00
2018-11-12 04:45:34 +08:00
Or to only run tests in a particular test module on Python 3.7::
2014-01-22 18:37:02 +08:00
2018-11-12 04:45:34 +08:00
$ tox -e py37 -- testing/test_config.py
2014-01-22 18:37:02 +08:00
2018-06-12 07:46:41 +08:00
When committing, `` pre-commit `` will re-format the files if necessary.
2015-03-03 03:48:09 +08:00
#. Commit and push once your tests pass and you are happy with your change(s)::
2014-01-22 18:37:02 +08:00
2015-06-16 05:54:44 +08:00
$ git commit -a -m "<commit message>"
$ git push -u
2014-01-22 18:37:02 +08:00
2017-07-23 02:58:12 +08:00
#. Create a new changelog entry in `` changelog `` . The file should be named `` <issueid>.<type> `` ,
where *issueid* is the number of the issue related to the change and *type* is one of
`` bugfix `` , `` removal `` , `` feature `` , `` vendor `` , `` doc `` or `` trivial `` .
#. Add yourself to `` AUTHORS `` file if not there yet, in alphabetical order.
2015-07-29 07:04:46 +08:00
2015-09-29 19:48:38 +08:00
#. Finally, submit a pull request through the GitHub website using this data::
2014-01-23 17:51:45 +08:00
2015-06-16 05:54:44 +08:00
head-fork: YOUR_GITHUB_USERNAME/pytest
compare: your-branch-name
2014-01-25 03:01:04 +08:00
2015-06-16 05:54:44 +08:00
base-fork: pytest-dev/pytest
2015-09-29 19:48:38 +08:00
base: master # if it's a bugfix
2016-06-22 15:13:01 +08:00
base: features # if it's a feature
2014-01-22 19:19:33 +08:00
2014-01-25 02:37:44 +08:00
2018-10-15 16:13:24 +08:00
Writing Tests
----------------------------
2018-10-15 19:00:16 +08:00
Writing tests for plugins or for pytest itself is often done using the `testdir fixture <https://docs.pytest.org/en/latest/reference.html#testdir> `_ , as a "black-box" test.
2018-10-15 16:13:24 +08:00
2018-10-15 19:00:16 +08:00
For example, to ensure a simple test passes you can write:
2018-10-15 16:13:24 +08:00
.. code-block :: python
def test_true_assertion(testdir):
testdir.makepyfile(
"""
def test_foo():
assert True
"""
)
result = testdir.runpytest()
result.assert_outcomes(failed=0, passed=1)
2018-10-15 19:00:16 +08:00
Alternatively, it is possible to make checks based on the actual output of the termal using
*glob-like* expressions:
.. code-block :: python
2018-10-15 16:13:24 +08:00
def test_true_assertion(testdir):
testdir.makepyfile(
"""
def test_foo():
assert False
"""
)
result = testdir.runpytest()
2018-10-15 19:15:40 +08:00
result.stdout.fnmatch_lines(["*assert False* ", "*1 failed* "])
2018-10-15 19:00:16 +08:00
When choosing a file where to write a new test, take a look at the existing files and see if there's
one file which looks like a good fit. For example, a regression test about a bug in the `` --lf `` option
should go into `` test_cacheprovider.py `` , given that this option is implemented in `` cacheprovider.py `` .
If in doubt, go ahead and open a PR with your best guess and we can discuss this over the code.
2018-10-15 16:13:24 +08:00
2016-11-18 05:25:22 +08:00
Joining the Development Team
----------------------------
Anyone who has successfully seen through a pull request which did not
require any extra work from the development team to merge will
2017-02-20 02:16:34 +08:00
themselves gain commit access if they so wish (if we forget to ask please send a friendly
2016-11-18 05:25:22 +08:00
reminder). This does not mean your workflow to contribute changes,
everyone goes through the same pull-request-and-review process and
2017-02-20 02:16:34 +08:00
no-one merges their own pull requests unless already approved. It does however mean you can
2016-11-18 05:25:22 +08:00
participate in the development process more fully since you can merge
pull requests from other contributors yourself after having reviewed
them.