File: contributing.rst

package info (click to toggle)
pytest-django 4.11.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 604 kB
  • sloc: python: 4,006; makefile: 39; sh: 17
file content (245 lines) | stat: -rw-r--r-- 9,074 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#############################
Contributing to pytest-django
#############################

Like every open-source project, pytest-django is always looking for motivated
individuals to contribute to its source code.  However, to ensure the highest
code quality and keep the repository nice and tidy, everybody has to follow a
few rules (nothing major, I promise :) )


*********
Community
*********

The fastest way to get feedback on contributions/bugs is usually to open an
issue in the `issue tracker`_.

Discussions also happen via IRC in #pytest `on irc.libera.chat
<ircs://irc.libera.chat:6697/#pytest>`_ (join using an IRC client, `via webchat
<https://web.libera.chat/#pytest>`_, or `via Matrix
<https://matrix.to/#/%23pytest:libera.chat>`_).
You may also be interested in following `@andreaspelme`_ on Twitter.

*************
In a nutshell
*************

Here's what the contribution process looks like, in a bullet-points fashion:

#. pytest-django is hosted on `GitHub`_, at
   https://github.com/pytest-dev/pytest-django
#. The best method to contribute back is to create an account there and fork
   the project. You can use this fork as if it was your own project, and should
   push your changes to it.
#. When you feel your code is good enough for inclusion, "send us a `pull
   request`_", by using the nice GitHub web interface.


*****************
Contributing Code
*****************


Getting the source code
=======================

- Code will be reviewed and tested by at least one core developer, preferably
  by several. Other community members are welcome to give feedback.
- Code *must* be tested. Your pull request should include unit-tests (that
  cover the piece of code you're submitting, obviously).
- Documentation should reflect your changes if relevant. There is nothing worse
  than invalid documentation.
- Usually, if unit tests are written, pass, and your change is relevant, then
  your pull request will be merged.

Since we're hosted on GitHub, pytest-django uses `git`_ as a version control
system.

The `GitHub help`_ is very well written and will get you started on using git
and GitHub in a jiffy. It is an invaluable resource for newbies and oldtimers
alike.


Syntax and conventions
======================

We try to conform to `PEP8`_ as much as possible. A few highlights:

- Indentation should be exactly 4 spaces. Not 2, not 6, not 8. **4**. Also,
  tabs are evil.
- We try (loosely) to keep the line length at 79 characters. Generally the rule
  is "it should look good in a terminal-based editor" (eg vim), but we try not
  be [Godwin's law] about it.


Process
=======

This is how you fix a bug or add a feature:

#. `fork`_ the repository on GitHub.
#. Checkout your fork.
#. Hack hack hack, test test test, commit commit commit, test again.
#. Push to your fork.
#. Open a pull request.


Tests
=====

Having a wide and comprehensive library of unit-tests and integration tests is
of exceeding importance. Contributing tests is widely regarded as a very
prestigious contribution (you're making everybody's future work much easier by
doing so). Good karma for you. Cookie points. Maybe even a beer if we meet in
person :)

Generally tests should be:

- Unitary (as much as possible). I.E. should test as much as possible only on
  one function/method/class. That's the very definition of unit tests.
  Integration tests are also interesting obviously, but require more time to
  maintain since they have a higher probability of breaking.
- Short running. No hard numbers here, but if your one test doubles the time it
  takes for everybody to run them, it's probably an indication that you're
  doing it wrong.

In a similar way to code, pull requests will be reviewed before pulling
(obviously), and we encourage discussion via code review (everybody learns
something this way) or in the IRC channel.

Running the tests
-----------------

There is a Makefile in the repository which aids in setting up a virtualenv
and running the tests::

    $ make test

You can manually create the virtualenv using::

    $ make testenv

This will install a virtualenv with pytest and the latest stable version of
Django. The virtualenv can then be activated with::

    $ source bin/activate

Then, simply invoke pytest to run the test suite::

    $ pytest --ds=pytest_django_test.settings_sqlite


tox can be used to run the test suite under different configurations by
invoking::

    $ tox

There is a huge number of unique test configurations (98 at the time of
writing), running them all will take a long time. All valid configurations can
be found in `tox.ini`. To test against a few of them, invoke tox with the `-e`
flag::

    $ tox -e py38-dj32-postgres,py310-dj41-mysql

This will run the tests on Python 3.8/Django 3.2/PostgeSQL and Python
3.10/Django 4.1/MySQL.


Measuring test coverage
-----------------------

Some of the tests are executed in subprocesses. Because of that regular
coverage measurements (using pytest-cov plugin) are not reliable.

If you want to measure coverage you'll need to create .pth file as described in
`subprocess section of coverage documentation`_. If you're using
editable mode you should uninstall pytest_django (using pip)
for the time of measuring coverage.

You'll also need mysql and postgres databases. There are predefined settings
for each database in the tests directory. You may want to modify these files
but please don't include them in your pull requests.

After this short initial setup you're ready to run tests::

    $ COVERAGE_PROCESS_START=`pwd`/pyproject.toml COVERAGE_FILE=`pwd`/.coverage pytest --ds=pytest_django_test.settings_postgres

You should repeat the above step for sqlite and mysql before the next step.
This step will create a lot of ``.coverage`` files with additional suffixes for
every process.

The final step is to combine all the files created by different processes and
generate the html coverage report::

    $ coverage combine
    $ coverage html

Your coverage report is now ready in the ``htmlcov`` directory.


Continuous integration
----------------------

`GitHub Actions`_ is used to automatically run all tests against all supported versions
of Python, Django and different database backends.

The `pytest-django Actions`_ page shows the latest test run. The CI will
automatically pick up pull requests, test them and report the result directly
in the pull request.

**************************
Contributing Documentation
**************************

Perhaps considered "boring" by hard-core coders, documentation is sometimes
even more important than code! This is what brings fresh blood to a project,
and serves as a reference for oldtimers. On top of this, documentation is the
one area where less technical people can help most - you just need to write a
semi-decent English. People need to understand you. We don't care about style
or correctness.

Documentation should be:

- We use `Sphinx`_/`restructuredText`_. So obviously this is the format you
  should use :) File extensions should be .rst.
- Written in English. We can discuss how it would bring more people to the
  project to have a Klingon translation or anything, but that's a problem we
  will ask ourselves when we already have a good documentation in English.
- Accessible. You should assume the reader to be moderately familiar with
  Python and Django, but not anything else. Link to documentation of libraries
  you use, for example, even if they are "obvious" to you (South is the first
  example that comes to mind - it's obvious to any Django programmer, but not
  to any newbie at all).
  A brief description of what it does is also welcome.

Pulling of documentation is pretty fast and painless. Usually somebody goes
over your text and merges it, since there are no "breaks" and that GitHub
parses rst files automagically it's really convenient to work with.

Also, contributing to the documentation will earn you great respect from the
core developers. You get good karma just like a test contributor, but you get
double cookie points. Seriously. You rock.


.. note::

  This very document is based on the contributing docs of the `django CMS`_
  project. Many thanks for allowing us to steal it!


.. _fork: https://github.com/pytest-dev/pytest-django
.. _issue tracker: https://github.com/pytest-dev/pytest-django/issues
.. _Sphinx: https://www.sphinx-doc.org/
.. _PEP8: https://www.python.org/dev/peps/pep-0008/
.. _GitHub : https://www.github.com
.. _GitHub help : https://help.github.com
.. _freenode : https://freenode.net/
.. _@andreaspelme : https://twitter.com/andreaspelme
.. _pull request : https://help.github.com/send-pull-requests/
.. _git : https://git-scm.com/
.. _restructuredText: https://docutils.sourceforge.io/docs/ref/rst/introduction.html
.. _django CMS: https://www.django-cms.org/
.. _GitHub Actions: https://github.com/features/actions
.. _pytest-django Actions: https://github.com/pytest-dev/pytest-django/actions
.. _`subprocess section of coverage documentation`: https://coverage.readthedocs.io/en/latest/subprocess.html