Skip to content

Commit 9f9af53

Browse files
committed
Expand on downstream testing, and add emphasis for readability
1 parent be242a8 commit 9f9af53

1 file changed

Lines changed: 43 additions & 17 deletions

File tree

source/discussions/downstream-packaging.rst

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -233,41 +233,67 @@ There is a number of things that you can do to help us test your package
233233
better. Some of them were already mentioned in this discussion. Some examples
234234
are:
235235

236-
- Include the test files and fixtures in the source distribution, or make it
236+
- **Include the test files and fixtures in the source distribution**, or make it
237237
possible to easily download them separately.
238238

239-
- Do not write to the package during testing. Downstream test setups sometimes
240-
run tests on top of the installed package, and test-time modifications can
241-
end up being part of the production package!
239+
- **Do not write to the package directories during testing.** Downstream test
240+
setups sometimes run tests on top of the installed package, and modifications
241+
performed during testing and temporary test files may end up being part
242+
of the installed package!
242243

243-
- Make the test suite work offline. Mock network interactions, using packages
244-
such as responses_ or vcrpy_. If that is not possible, make it possible
245-
to easily disable the tests using Internet access, e.g. via a pytest marker.
246-
Use pytest-socket_ to verify that your tests work offline.
244+
- **Make the test suite work offline.** Mock network interactions, using
245+
packages such as responses_ or vcrpy_. If that is not possible, make it
246+
possible to easily disable the tests using Internet access, e.g. via a pytest
247+
marker. Use pytest-socket_ to verify that your tests work offline. This
248+
often makes your own test workflows faster and more reliable as well.
247249

248-
- Make your tests work without a specialized setup, or perform the necessary
250+
- **Make your tests work without a specialized setup**, or perform the necessary
249251
setup as part of test fixtures. Do not ever assume that you can connect
250252
to system services such as databases — in an extreme case, you could crash
251253
a production service!
252254

253-
- Do not assume that the test suite will be run with ``-Werror``. Downstreams
255+
- **If your package has optional dependencies, make their tests optional as
256+
well.** Either skip them if the needed packages are not installed, or add
257+
markers to make deselecting easy.
258+
259+
- More generally, **add markers to tests with special requirements**. These can
260+
include e.g. significant space usage, significant memory usage, long runtime,
261+
incompatibility with parallel testing.
262+
263+
- **Do not assume that the test suite will be run with -Werror.** Downstreams
254264
often need to disable that, as it causes false positives, e.g. due to newer
255265
dependency versions. Assert for warnings using ``pytest.warns()`` rather
256266
than ``pytest.raises()``!
257267

258-
- Aim to make your test suite reliable. Avoid flaky tests. Avoid depending
259-
on specific platform details, don't rely on exact results of floating-point
260-
computation, or timing of operations, and so on. Fuzzing has its advantages,
261-
but you want to have static test cases for completeness as well.
268+
- **Aim to make your test suite reliable and reproducible.** Avoid flaky tests.
269+
Avoid depending on specific platform details, don't rely on exact results
270+
of floating-point computation, or timing of operations, and so on. Fuzzing
271+
has its advantages, but you want to have static test cases for completeness
272+
as well.
262273

263-
- Split tests by their purpose, and make it easy to skip categories that are
264-
irrelevant or problematic. Since the primary purpose of downstream testing is
265-
to ensure that the package itself works, we generally are not interested
274+
- **Split tests by their purpose, and make it easy to skip categories that are
275+
irrelevant or problematic.** Since the primary purpose of downstream testing
276+
is to ensure that the package itself works, we generally are not interested
266277
in e.g. checking code coverage, code formatting, typing or running
267278
benchmarks. These tests can fail as dependencies are upgraded or the system
268279
is under load, without actually affecting the package itself.
269280

281+
- If your test suite takes significant time to run, **support testing
282+
in parallel.** Downstreams often maintain a large number of packages,
283+
and testing them all takes a lot of time. Using pytest-xdist_ can help them
284+
avoid bottlenecks.
285+
286+
- Ideally, **support running your test suite via PyTest**. PyTest_ has many
287+
command-line arguments that are truly helpful to downstreams, such as
288+
the ability to conveniently deselect tests, rerun flaky tests
289+
(via pytest-rerunfailures_), add a timeout to prevent tests from hanging
290+
(via pytest-timeout_) or run tests in parallel (via pytest-xdist_).
291+
270292

271293
.. _responses: https://pypi.org/project/responses/
272294
.. _vcrpy: https://pypi.org/project/vcrpy/
273295
.. _pytest-socket: https://pypi.org/project/pytest-socket/
296+
.. _pytest-xdist: https://pypi.org/project/pytest-xdist/
297+
.. _pytest: https://pytest.org/
298+
.. _pytest-rerunfailures: https://pypi.org/project/pytest-rerunfailures/
299+
.. _pytest-timeout: https://pypi.org/project/pytest-timeout/

0 commit comments

Comments
 (0)