Debian Codegraph @

testing/web-platform/tests/tools/third_party/pytest/CONTRIBUTING.rst

raw
1 ============================
2 Contribution getting started
3 ============================
4
5 Contributions are highly welcomed and appreciated. Every little bit of help counts,
6 so do not hesitate!
7
8 .. contents::
9 :depth: 2
10 :backlinks: none
11
12
13 .. _submitfeedback:
14
15 Feature requests and feedback
16 -----------------------------
17
18 Do you like pytest? Share some love on Twitter or in your blog posts!
19
20 We'd also like to hear about your propositions and suggestions. Feel free to
21 `submit them as issues <https://github.com/pytest-dev/pytest/issues>`_ and:
22
23 * Explain in detail how they should work.
24 * Keep the scope as narrow as possible. This will make it easier to implement.
25
26
27 .. _reportbugs:
28
29 Report bugs
30 -----------
31
32 Report bugs for pytest in the `issue tracker <https://github.com/pytest-dev/pytest/issues>`_.
33
34 If you are reporting a bug, please include:
35
36 * Your operating system name and version.
37 * Any details about your local setup that might be helpful in troubleshooting,
38 specifically the Python interpreter version, installed libraries, and pytest
39 version.
40 * Detailed steps to reproduce the bug.
41
42 If you can write a demonstration test that currently fails but should pass
43 (xfail), that is a very useful commit to make as well, even if you cannot
44 fix the bug itself.
45
46
47 .. _fixbugs:
48
49 Fix bugs
50 --------
51
52 Look through the `GitHub issues for bugs <https://github.com/pytest-dev/pytest/labels/type:%20bug>`_.
53 See also the `"good first issue" issues <https://github.com/pytest-dev/pytest/labels/good%20first%20issue>`_
54 that are friendly to new contributors.
55
56 :ref:`Talk <contact>` to developers to find out how you can fix specific bugs. To indicate that you are going
57 to work on a particular issue, add a comment to that effect on the specific issue.
58
59 Don't forget to check the issue trackers of your favourite plugins, too!
60
61 .. _writeplugins:
62
63 Implement features
64 ------------------
65
66 Look through the `GitHub issues for enhancements <https://github.com/pytest-dev/pytest/labels/type:%20enhancement>`_.
67
68 :ref:`Talk <contact>` to developers to find out how you can implement specific
69 features.
70
71 Write documentation
72 -------------------
73
74 Pytest could always use more documentation. What exactly is needed?
75
76 * More complementary documentation. Have you perhaps found something unclear?
77 * Documentation translations. We currently have only English.
78 * Docstrings. There can never be too many of them.
79 * Blog posts, articles and such -- they're all very appreciated.
80
81 You can also edit documentation files directly in the GitHub web interface,
82 without using a local copy. This can be convenient for small fixes.
83
84 .. note::
85 Build the documentation locally with the following command:
86
87 .. code:: bash
88
89 $ tox -e docs
90
91 The built documentation should be available in ``doc/en/_build/html``,
92 where 'en' refers to the documentation language.
93
94 Pytest has an API reference which in large part is
95 `generated automatically <https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html>`_
96 from the docstrings of the documented items. Pytest uses the
97 `Sphinx docstring format <https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html>`_.
98 For example:
99
100 .. code-block:: python
101
102 def my_function(arg: ArgType) -> Foo:
103 """Do important stuff.
104
105 More detailed info here, in separate paragraphs from the subject line.
106 Use proper sentences -- start sentences with capital letters and end
107 with periods.
108
109 Can include annotated documentation:
110
111 :param short_arg: An argument which determines stuff.
112 :param long_arg:
113 A long explanation which spans multiple lines, overflows
114 like this.
115 :returns: The result.
116 :raises ValueError:
117 Detailed information when this can happen.
118
119 .. versionadded:: 6.0
120
121 Including types into the annotations above is not necessary when
122 type-hinting is being used (as in this example).
123 """
124
125
126 .. _submitplugin:
127
128 Submitting Plugins to pytest-dev
129 --------------------------------
130
131 Pytest development of the core, some plugins and support code happens
132 in repositories living under the ``pytest-dev`` organisations:
133
134 - `pytest-dev on GitHub <https://github.com/pytest-dev>`_
135
136 All pytest-dev Contributors team members have write access to all contained
137 repositories. Pytest core and plugins are generally developed
138 using `pull requests`_ to respective repositories.
139
140 The objectives of the ``pytest-dev`` organisation are:
141
142 * Having a central location for popular pytest plugins
143 * Sharing some of the maintenance responsibility (in case a maintainer no
144 longer wishes to maintain a plugin)
145
146 You can submit your plugin by subscribing to the `pytest-dev mail list
147 <https://mail.python.org/mailman/listinfo/pytest-dev>`_ and writing a
148 mail pointing to your existing pytest plugin repository which must have
149 the following:
150
151 - PyPI presence with packaging metadata that contains a ``pytest-``
152 prefixed name, version number, authors, short and long description.
153
154 - a `tox configuration <https://tox.readthedocs.io/en/latest/config.html#configuration-discovery>`_
155 for running tests using `tox <https://tox.readthedocs.io>`_.
156
157 - a ``README`` describing how to use the plugin and on which
158 platforms it runs.
159
160 - a ``LICENSE`` file containing the licensing information, with
161 matching info in its packaging metadata.
162
163 - an issue tracker for bug reports and enhancement requests.
164
165 - a `changelog <https://keepachangelog.com/>`_.
166
167 If no contributor strongly objects and two agree, the repository can then be
168 transferred to the ``pytest-dev`` organisation.
169
170 Here's a rundown of how a repository transfer usually proceeds
171 (using a repository named ``joedoe/pytest-xyz`` as example):
172
173 * ``joedoe`` transfers repository ownership to ``pytest-dev`` administrator ``calvin``.
174 * ``calvin`` creates ``pytest-xyz-admin`` and ``pytest-xyz-developers`` teams, inviting ``joedoe`` to both as **maintainer**.
175 * ``calvin`` transfers repository to ``pytest-dev`` and configures team access:
176
177 - ``pytest-xyz-admin`` **admin** access;
178 - ``pytest-xyz-developers`` **write** access;
179
180 The ``pytest-dev/Contributors`` team has write access to all projects, and
181 every project administrator is in it. We recommend that each plugin has at least three
182 people who have the right to release to PyPI.
183
184 Repository owners can rest assured that no ``pytest-dev`` administrator will ever make
185 releases of your repository or take ownership in any way, except in rare cases
186 where someone becomes unresponsive after months of contact attempts.
187 As stated, the objective is to share maintenance and avoid "plugin-abandon".
188
189
190 .. _`pull requests`:
191 .. _pull-requests:
192
193 Preparing Pull Requests
194 -----------------------
195
196 Short version
197 ~~~~~~~~~~~~~
198
199 #. Fork the repository.
200 #. Fetch tags from upstream if necessary (if you cloned only main `git fetch --tags https://github.com/pytest-dev/pytest`).
201 #. Enable and install `pre-commit <https://pre-commit.com>`_ to ensure style-guides and code checks are followed.
202 #. Follow `PEP-8 <https://www.python.org/dev/peps/pep-0008/>`_ for naming.
203 #. Tests are run using ``tox``::
204
205 tox -e linting,py39
206
207 The test environments above are usually enough to cover most cases locally.
208
209 #. Write a ``changelog`` entry: ``changelog/2574.bugfix.rst``, use issue id number
210 and one of ``feature``, ``improvement``, ``bugfix``, ``doc``, ``deprecation``,
211 ``breaking``, ``vendor`` or ``trivial`` for the issue type.
212
213
214 #. Unless your change is a trivial or a documentation fix (e.g., a typo or reword of a small section) please
215 add yourself to the ``AUTHORS`` file, in alphabetical order.
216
217
218 Long version
219 ~~~~~~~~~~~~
220
221 What is a "pull request"? It informs the project's core developers about the
222 changes you want to review and merge. Pull requests are stored on
223 `GitHub servers <https://github.com/pytest-dev/pytest/pulls>`_.
224 Once you send a pull request, we can discuss its potential modifications and
225 even add more commits to it later on. There's an excellent tutorial on how Pull
226 Requests work in the
227 `GitHub Help Center <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests>`_.
228
229 Here is a simple overview, with pytest-specific bits:
230
231 #. Fork the
232 `pytest GitHub repository <https://github.com/pytest-dev/pytest>`__. It's
233 fine to use ``pytest`` as your fork repository name because it will live
234 under your user.
235
236 #. Clone your fork locally using `git <https://git-scm.com/>`_ and create a branch::
237
238 $ git clone [email protected]:YOUR_GITHUB_USERNAME/pytest.git
239 $ cd pytest
240 $ git fetch --tags https://github.com/pytest-dev/pytest
241 # now, create your own branch off "main":
242
243 $ git checkout -b your-bugfix-branch-name main
244
245 Given we have "major.minor.micro" version numbers, bug fixes will usually
246 be released in micro releases whereas features will be released in
247 minor releases and incompatible changes in major releases.
248
249 You will need the tags to test locally, so be sure you have the tags from the main repository. If you suspect you don't, set the main repository as upstream and fetch the tags::
250
251 $ git remote add upstream https://github.com/pytest-dev/pytest
252 $ git fetch upstream --tags
253
254 If you need some help with Git, follow this quick start
255 guide: https://git.wiki.kernel.org/index.php/QuickStart
256
257 #. Install `pre-commit <https://pre-commit.com>`_ and its hook on the pytest repo::
258
259 $ pip install --user pre-commit
260 $ pre-commit install
261
262 Afterwards ``pre-commit`` will run whenever you commit.
263
264 https://pre-commit.com/ is a framework for managing and maintaining multi-language pre-commit hooks
265 to ensure code-style and code formatting is consistent.
266
267 #. Install tox
268
269 Tox is used to run all the tests and will automatically setup virtualenvs
270 to run the tests in.
271 (will implicitly use https://virtualenv.pypa.io/en/latest/)::
272
273 $ pip install tox
274
275 #. Run all the tests
276
277 You need to have Python 3.8 or later available in your system. Now
278 running tests is as simple as issuing this command::
279
280 $ tox -e linting,py39
281
282 This command will run tests via the "tox" tool against Python 3.9
283 and also perform "lint" coding-style checks.
284
285 #. You can now edit your local working copy and run the tests again as necessary. Please follow `PEP-8 <https://www.python.org/dev/peps/pep-0008/>`_ for naming.
286
287 You can pass different options to ``tox``. For example, to run tests on Python 3.9 and pass options to pytest
288 (e.g. enter pdb on failure) to pytest you can do::
289
290 $ tox -e py39 -- --pdb
291
292 Or to only run tests in a particular test module on Python 3.9::
293
294 $ tox -e py39 -- testing/test_config.py
295
296
297 When committing, ``pre-commit`` will re-format the files if necessary.
298
299 #. If instead of using ``tox`` you prefer to run the tests directly, then we suggest to create a virtual environment and use
300 an editable install with the ``dev`` extra::
301
302 $ python3 -m venv .venv
303 $ source .venv/bin/activate # Linux
304 $ .venv/Scripts/activate.bat # Windows
305 $ pip install -e ".[dev]"
306
307 Afterwards, you can edit the files and run pytest normally::
308
309 $ pytest testing/test_config.py
310
311 #. Create a new changelog entry in ``changelog``. The file should be named ``<issueid>.<type>.rst``,
312 where *issueid* is the number of the issue related to the change and *type* is one of
313 ``feature``, ``improvement``, ``bugfix``, ``doc``, ``deprecation``, ``breaking``, ``vendor``
314 or ``trivial``. You may skip creating the changelog entry if the change doesn't affect the
315 documented behaviour of pytest.
316
317 #. Add yourself to ``AUTHORS`` file if not there yet, in alphabetical order.
318
319 #. Commit and push once your tests pass and you are happy with your change(s)::
320
321 $ git commit -a -m "<commit message>"
322 $ git push -u
323
324 #. Finally, submit a pull request through the GitHub website using this data::
325
326 head-fork: YOUR_GITHUB_USERNAME/pytest
327 compare: your-branch-name
328
329 base-fork: pytest-dev/pytest
330 base: main
331
332
333 Writing Tests
334 ~~~~~~~~~~~~~
335
336 Writing tests for plugins or for pytest itself is often done using the `pytester fixture <https://docs.pytest.org/en/stable/reference/reference.html#pytester>`_, as a "black-box" test.
337
338 For example, to ensure a simple test passes you can write:
339
340 .. code-block:: python
341
342 def test_true_assertion(pytester):
343 pytester.makepyfile(
344 """
345 def test_foo():
346 assert True
347 """
348 )
349 result = pytester.runpytest()
350 result.assert_outcomes(failed=0, passed=1)
351
352
353 Alternatively, it is possible to make checks based on the actual output of the termal using
354 *glob-like* expressions:
355
356 .. code-block:: python
357
358 def test_true_assertion(pytester):
359 pytester.makepyfile(
360 """
361 def test_foo():
362 assert False
363 """
364 )
365 result = pytester.runpytest()
366 result.stdout.fnmatch_lines(["*assert False*", "*1 failed*"])
367
368 When choosing a file where to write a new test, take a look at the existing files and see if there's
369 one file which looks like a good fit. For example, a regression test about a bug in the ``--lf`` option
370 should go into ``test_cacheprovider.py``, given that this option is implemented in ``cacheprovider.py``.
371 If in doubt, go ahead and open a PR with your best guess and we can discuss this over the code.
372
373 Joining the Development Team
374 ----------------------------
375
376 Anyone who has successfully seen through a pull request which did not
377 require any extra work from the development team to merge will
378 themselves gain commit access if they so wish (if we forget to ask please send a friendly
379 reminder). This does not mean there is any change in your contribution workflow:
380 everyone goes through the same pull-request-and-review process and
381 no-one merges their own pull requests unless already approved. It does however mean you can
382 participate in the development process more fully since you can merge
383 pull requests from other contributors yourself after having reviewed
384 them.
385
386
387 Backporting bug fixes for the next patch release
388 ------------------------------------------------
389
390 Pytest makes a feature release every few weeks or months. In between, patch releases
391 are made to the previous feature release, containing bug fixes only. The bug fixes
392 usually fix regressions, but may be any change that should reach users before the
393 next feature release.
394
395 Suppose for example that the latest release was 1.2.3, and you want to include
396 a bug fix in 1.2.4 (check https://github.com/pytest-dev/pytest/releases for the
397 actual latest release). The procedure for this is:
398
399 #. First, make sure the bug is fixed in the ``main`` branch, with a regular pull
400 request, as described above. An exception to this is if the bug fix is not
401 applicable to ``main`` anymore.
402
403 Automatic method:
404
405 Add a ``backport 1.2.x`` label to the PR you want to backport. This will create
406 a backport PR against the ``1.2.x`` branch.
407
408 Manual method:
409
410 #. ``git checkout origin/1.2.x -b backport-XXXX`` # use the main PR number here
411
412 #. Locate the merge commit on the PR, in the *merged* message, for example:
413
414 nicoddemus merged commit 0f8b462 into pytest-dev:main
415
416 #. ``git cherry-pick -x -m1 REVISION`` # use the revision you found above (``0f8b462``).
417
418 #. Open a PR targeting ``1.2.x``:
419
420 * Prefix the message with ``[1.2.x]``.
421 * Delete the PR body, it usually contains a duplicate commit message.
422
423
424 Who does the backporting
425 ~~~~~~~~~~~~~~~~~~~~~~~~
426
427 As mentioned above, bugs should first be fixed on ``main`` (except in rare occasions
428 that a bug only happens in a previous release). So, who should do the backport procedure described
429 above?
430
431 1. If the bug was fixed by a core developer, it is the main responsibility of that core developer
432 to do the backport.
433 2. However, often the merge is done by another maintainer, in which case it is nice of them to
434 do the backport procedure if they have the time.
435 3. For bugs submitted by non-maintainers, it is expected that a core developer will to do
436 the backport, normally the one that merged the PR on ``main``.
437 4. If a non-maintainers notices a bug which is fixed on ``main`` but has not been backported
438 (due to maintainers forgetting to apply the *needs backport* label, or just plain missing it),
439 they are also welcome to open a PR with the backport. The procedure is simple and really
440 helps with the maintenance of the project.
441
442 All the above are not rules, but merely some guidelines/suggestions on what we should expect
443 about backports.
444
445 Handling stale issues/PRs
446 -------------------------
447
448 Stale issues/PRs are those where pytest contributors have asked for questions/changes
449 and the authors didn't get around to answer/implement them yet after a somewhat long time, or
450 the discussion simply died because people seemed to lose interest.
451
452 There are many reasons why people don't answer questions or implement requested changes:
453 they might get busy, lose interest, or just forget about it,
454 but the fact is that this is very common in open source software.
455
456 The pytest team really appreciates every issue and pull request, but being a high-volume project
457 with many issues and pull requests being submitted daily, we try to reduce the number of stale
458 issues and PRs by regularly closing them. When an issue/pull request is closed in this manner,
459 it is by no means a dismissal of the topic being tackled by the issue/pull request, but it
460 is just a way for us to clear up the queue and make the maintainers' work more manageable. Submitters
461 can always reopen the issue/pull request in their own time later if it makes sense.
462
463 When to close
464 ~~~~~~~~~~~~~
465
466 Here are a few general rules the maintainers use deciding when to close issues/PRs because
467 of lack of inactivity:
468
469 * Issues labeled ``question`` or ``needs information``: closed after 14 days inactive.
470 * Issues labeled ``proposal``: closed after six months inactive.
471 * Pull requests: after one month, consider pinging the author, update linked issue, or consider closing. For pull requests which are nearly finished, the team should consider finishing it up and merging it.
472
473 The above are **not hard rules**, but merely **guidelines**, and can be (and often are!) reviewed on a case-by-case basis.
474
475 Closing pull requests
476 ~~~~~~~~~~~~~~~~~~~~~
477
478 When closing a Pull Request, it needs to be acknowledging the time, effort, and interest demonstrated by the person which submitted it. As mentioned previously, it is not the intent of the team to dismiss a stalled pull request entirely but to merely to clear up our queue, so a message like the one below is warranted when closing a pull request that went stale:
479
480 Hi <contributor>,
481
482 First of all, we would like to thank you for your time and effort on working on this, the pytest team deeply appreciates it.
483
484 We noticed it has been awhile since you have updated this PR, however. pytest is a high activity project, with many issues/PRs being opened daily, so it is hard for us maintainers to track which PRs are ready for merging, for review, or need more attention.
485
486 So for those reasons we, think it is best to close the PR for now, but with the only intention to clean up our queue, it is by no means a rejection of your changes. We still encourage you to re-open this PR (it is just a click of a button away) when you are ready to get back to it.
487
488 Again we appreciate your time for working on this, and hope you might get back to this at a later time!
489
490 <bye>
491
492 Closing Issues
493 --------------
494
495 When a pull request is submitted to fix an issue, add text like ``closes #XYZW`` to the PR description and/or commits (where ``XYZW`` is the issue number). See the `GitHub docs <https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword>`_ for more information.
496
497 When an issue is due to user error (e.g. misunderstanding of a functionality), please politely explain to the user why the issue raised is really a non-issue and ask them to close the issue if they have no further questions. If the original requestor is unresponsive, the issue will be handled as described in the section `Handling stale issues/PRs`_ above.