CONTRIBUTING.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. ============================
  2. Contribution getting started
  3. ============================
  4. Contributions are highly welcomed and appreciated. Every little help counts,
  5. so do not hesitate!
  6. .. contents:: Contribution links
  7. :depth: 2
  8. .. _submitfeedback:
  9. Feature requests and feedback
  10. -----------------------------
  11. Do you like pytest? Share some love on Twitter or in your blog posts!
  12. We'd also like to hear about your propositions and suggestions. Feel free to
  13. `submit them as issues <https://github.com/pytest-dev/pytest/issues>`_ and:
  14. * Explain in detail how they should work.
  15. * Keep the scope as narrow as possible. This will make it easier to implement.
  16. .. _reportbugs:
  17. Report bugs
  18. -----------
  19. Report bugs for pytest in the `issue tracker <https://github.com/pytest-dev/pytest/issues>`_.
  20. If you are reporting a bug, please include:
  21. * Your operating system name and version.
  22. * Any details about your local setup that might be helpful in troubleshooting,
  23. specifically the Python interpreter version, installed libraries, and pytest
  24. version.
  25. * Detailed steps to reproduce the bug.
  26. If you can write a demonstration test that currently fails but should pass
  27. (xfail), that is a very useful commit to make as well, even if you cannot
  28. fix the bug itself.
  29. .. _fixbugs:
  30. Fix bugs
  31. --------
  32. Look through the `GitHub issues for bugs <https://github.com/pytest-dev/pytest/labels/type:%20bug>`_.
  33. :ref:`Talk <contact>` to developers to find out how you can fix specific bugs.
  34. Don't forget to check the issue trackers of your favourite plugins, too!
  35. .. _writeplugins:
  36. Implement features
  37. ------------------
  38. Look through the `GitHub issues for enhancements <https://github.com/pytest-dev/pytest/labels/type:%20enhancement>`_.
  39. :ref:`Talk <contact>` to developers to find out how you can implement specific
  40. features.
  41. Write documentation
  42. -------------------
  43. Pytest could always use more documentation. What exactly is needed?
  44. * More complementary documentation. Have you perhaps found something unclear?
  45. * Documentation translations. We currently have only English.
  46. * Docstrings. There can never be too many of them.
  47. * Blog posts, articles and such -- they're all very appreciated.
  48. You can also edit documentation files directly in the GitHub web interface,
  49. without using a local copy. This can be convenient for small fixes.
  50. .. note::
  51. Build the documentation locally with the following command:
  52. .. code:: bash
  53. $ tox -e docs
  54. The built documentation should be available in the ``doc/en/_build/``.
  55. Where 'en' refers to the documentation language.
  56. .. _submitplugin:
  57. Submitting Plugins to pytest-dev
  58. --------------------------------
  59. Pytest development of the core, some plugins and support code happens
  60. in repositories living under the ``pytest-dev`` organisations:
  61. - `pytest-dev on GitHub <https://github.com/pytest-dev>`_
  62. - `pytest-dev on Bitbucket <https://bitbucket.org/pytest-dev>`_
  63. All pytest-dev Contributors team members have write access to all contained
  64. repositories. Pytest core and plugins are generally developed
  65. using `pull requests`_ to respective repositories.
  66. The objectives of the ``pytest-dev`` organisation are:
  67. * Having a central location for popular pytest plugins
  68. * Sharing some of the maintenance responsibility (in case a maintainer no
  69. longer wishes to maintain a plugin)
  70. You can submit your plugin by subscribing to the `pytest-dev mail list
  71. <https://mail.python.org/mailman/listinfo/pytest-dev>`_ and writing a
  72. mail pointing to your existing pytest plugin repository which must have
  73. the following:
  74. - PyPI presence with a ``setup.py`` that contains a license, ``pytest-``
  75. prefixed name, version number, authors, short and long description.
  76. - a ``tox.ini`` for running tests using `tox <https://tox.readthedocs.io>`_.
  77. - a ``README.txt`` describing how to use the plugin and on which
  78. platforms it runs.
  79. - a ``LICENSE.txt`` file or equivalent containing the licensing
  80. information, with matching info in ``setup.py``.
  81. - an issue tracker for bug reports and enhancement requests.
  82. - a `changelog <http://keepachangelog.com/>`_
  83. If no contributor strongly objects and two agree, the repository can then be
  84. transferred to the ``pytest-dev`` organisation.
  85. Here's a rundown of how a repository transfer usually proceeds
  86. (using a repository named ``joedoe/pytest-xyz`` as example):
  87. * ``joedoe`` transfers repository ownership to ``pytest-dev`` administrator ``calvin``.
  88. * ``calvin`` creates ``pytest-xyz-admin`` and ``pytest-xyz-developers`` teams, inviting ``joedoe`` to both as **maintainer**.
  89. * ``calvin`` transfers repository to ``pytest-dev`` and configures team access:
  90. - ``pytest-xyz-admin`` **admin** access;
  91. - ``pytest-xyz-developers`` **write** access;
  92. The ``pytest-dev/Contributors`` team has write access to all projects, and
  93. every project administrator is in it. We recommend that each plugin has at least three
  94. people who have the right to release to PyPI.
  95. Repository owners can rest assured that no ``pytest-dev`` administrator will ever make
  96. releases of your repository or take ownership in any way, except in rare cases
  97. where someone becomes unresponsive after months of contact attempts.
  98. As stated, the objective is to share maintenance and avoid "plugin-abandon".
  99. .. _`pull requests`:
  100. .. _pull-requests:
  101. Preparing Pull Requests
  102. -----------------------
  103. Short version
  104. ~~~~~~~~~~~~~
  105. #. Fork the repository.
  106. #. Enable and install `pre-commit <https://pre-commit.com>`_ to ensure style-guides and code checks are followed.
  107. #. Target ``master`` for bugfixes and doc changes.
  108. #. Target ``features`` for new features or functionality changes.
  109. #. Follow **PEP-8** for naming and `black <https://github.com/python/black>`_ for formatting.
  110. #. Tests are run using ``tox``::
  111. tox -e linting,py27,py37
  112. The test environments above are usually enough to cover most cases locally.
  113. #. Write a ``changelog`` entry: ``changelog/2574.bugfix``, use issue id number
  114. and one of ``bugfix``, ``removal``, ``feature``, ``vendor``, ``doc`` or
  115. ``trivial`` for the issue type.
  116. #. Unless your change is a trivial or a documentation fix (e.g., a typo or reword of a small section) please
  117. add yourself to the ``AUTHORS`` file, in alphabetical order.
  118. Long version
  119. ~~~~~~~~~~~~
  120. What is a "pull request"? It informs the project's core developers about the
  121. changes you want to review and merge. Pull requests are stored on
  122. `GitHub servers <https://github.com/pytest-dev/pytest/pulls>`_.
  123. Once you send a pull request, we can discuss its potential modifications and
  124. even add more commits to it later on. There's an excellent tutorial on how Pull
  125. Requests work in the
  126. `GitHub Help Center <https://help.github.com/articles/using-pull-requests/>`_.
  127. Here is a simple overview, with pytest-specific bits:
  128. #. Fork the
  129. `pytest GitHub repository <https://github.com/pytest-dev/pytest>`__. It's
  130. fine to use ``pytest`` as your fork repository name because it will live
  131. under your user.
  132. #. Clone your fork locally using `git <https://git-scm.com/>`_ and create a branch::
  133. $ git clone git@github.com:YOUR_GITHUB_USERNAME/pytest.git
  134. $ cd pytest
  135. # now, to fix a bug create your own branch off "master":
  136. $ git checkout -b your-bugfix-branch-name master
  137. # or to instead add a feature create your own branch off "features":
  138. $ git checkout -b your-feature-branch-name features
  139. Given we have "major.minor.micro" version numbers, bugfixes will usually
  140. be released in micro releases whereas features will be released in
  141. minor releases and incompatible changes in major releases.
  142. If you need some help with Git, follow this quick start
  143. guide: https://git.wiki.kernel.org/index.php/QuickStart
  144. #. Install `pre-commit <https://pre-commit.com>`_ and its hook on the pytest repo::
  145. $ pip install --user pre-commit
  146. $ pre-commit install
  147. Afterwards ``pre-commit`` will run whenever you commit.
  148. https://pre-commit.com/ is a framework for managing and maintaining multi-language pre-commit hooks
  149. to ensure code-style and code formatting is consistent.
  150. #. Install tox
  151. Tox is used to run all the tests and will automatically setup virtualenvs
  152. to run the tests in.
  153. (will implicitly use http://www.virtualenv.org/en/latest/)::
  154. $ pip install tox
  155. #. Run all the tests
  156. You need to have Python 2.7 and 3.7 available in your system. Now
  157. running tests is as simple as issuing this command::
  158. $ tox -e linting,py27,py37
  159. This command will run tests via the "tox" tool against Python 2.7 and 3.7
  160. and also perform "lint" coding-style checks.
  161. #. You can now edit your local working copy and run the tests again as necessary. Please follow PEP-8 for naming.
  162. You can pass different options to ``tox``. For example, to run tests on Python 2.7 and pass options to pytest
  163. (e.g. enter pdb on failure) to pytest you can do::
  164. $ tox -e py27 -- --pdb
  165. Or to only run tests in a particular test module on Python 3.7::
  166. $ tox -e py37 -- testing/test_config.py
  167. When committing, ``pre-commit`` will re-format the files if necessary.
  168. #. Commit and push once your tests pass and you are happy with your change(s)::
  169. $ git commit -a -m "<commit message>"
  170. $ git push -u
  171. #. Create a new changelog entry in ``changelog``. The file should be named ``<issueid>.<type>``,
  172. where *issueid* is the number of the issue related to the change and *type* is one of
  173. ``bugfix``, ``removal``, ``feature``, ``vendor``, ``doc`` or ``trivial``.
  174. #. Add yourself to ``AUTHORS`` file if not there yet, in alphabetical order.
  175. #. Finally, submit a pull request through the GitHub website using this data::
  176. head-fork: YOUR_GITHUB_USERNAME/pytest
  177. compare: your-branch-name
  178. base-fork: pytest-dev/pytest
  179. base: master # if it's a bugfix
  180. base: features # if it's a feature
  181. Writing Tests
  182. ----------------------------
  183. 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.
  184. For example, to ensure a simple test passes you can write:
  185. .. code-block:: python
  186. def test_true_assertion(testdir):
  187. testdir.makepyfile(
  188. """
  189. def test_foo():
  190. assert True
  191. """
  192. )
  193. result = testdir.runpytest()
  194. result.assert_outcomes(failed=0, passed=1)
  195. Alternatively, it is possible to make checks based on the actual output of the termal using
  196. *glob-like* expressions:
  197. .. code-block:: python
  198. def test_true_assertion(testdir):
  199. testdir.makepyfile(
  200. """
  201. def test_foo():
  202. assert False
  203. """
  204. )
  205. result = testdir.runpytest()
  206. result.stdout.fnmatch_lines(["*assert False*", "*1 failed*"])
  207. When choosing a file where to write a new test, take a look at the existing files and see if there's
  208. one file which looks like a good fit. For example, a regression test about a bug in the ``--lf`` option
  209. should go into ``test_cacheprovider.py``, given that this option is implemented in ``cacheprovider.py``.
  210. If in doubt, go ahead and open a PR with your best guess and we can discuss this over the code.
  211. Joining the Development Team
  212. ----------------------------
  213. Anyone who has successfully seen through a pull request which did not
  214. require any extra work from the development team to merge will
  215. themselves gain commit access if they so wish (if we forget to ask please send a friendly
  216. reminder). This does not mean your workflow to contribute changes,
  217. everyone goes through the same pull-request-and-review process and
  218. no-one merges their own pull requests unless already approved. It does however mean you can
  219. participate in the development process more fully since you can merge
  220. pull requests from other contributors yourself after having reviewed
  221. them.