Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
96058cc
Start a discussion on helping downstream packaging
mgorny Jan 27, 2025
b4cb7d2
Add a section on Internet access
mgorny Jan 27, 2025
df7081c
Also suggest the option of splitting test data into separate archive
mgorny Jan 27, 2025
cff76df
Add a section on system dependencies
mgorny Jan 28, 2025
be242a8
Add a section on downstream testing
mgorny Jan 28, 2025
9f9af53
Expand on downstream testing, and add emphasis for readability
mgorny Jan 29, 2025
00f39e5
Reorganize into why/how sections, and add emphasis
mgorny Jan 29, 2025
08c70e8
Elaborate a bit more on why it's good to help downstreams
mgorny Jan 29, 2025
24f552e
Correct "pytest" capitalization
mgorny Jan 29, 2025
24b0346
Apply suggestions from code review
mgorny Jan 30, 2025
16288af
Apply more suggestions from code review
mgorny Jan 30, 2025
b4c7485
Attempt addressing the remaining review comments
mgorny Jan 30, 2025
df0c91a
Add a section on stable channels
mgorny Jan 30, 2025
fc72a38
Retitle as "Supporting downstream packaging"
mgorny Jan 31, 2025
24462f4
Add a "not all-or-nothing" sentence
mgorny Jan 31, 2025
29cc38a
Add a note that downstreams can send patches to fix these issues
mgorny Jan 31, 2025
9d5fbe6
Capitalize Git, per @pawamoy
mgorny Feb 1, 2025
4d95da2
Fix inconsistent case in bullet points and remove duplicate
mgorny Feb 1, 2025
6f55709
Apply typo fixes, thanks to @pawamoy
mgorny Feb 1, 2025
548ab34
Clarify that source distribution needs only package's files
mgorny Feb 1, 2025
e925da1
Fix inconsistent whitespace between sentences
mgorny Feb 1, 2025
0eb407c
Make the point of reusing source distribution lighter
mgorny Feb 1, 2025
94743f9
Clarify the Internet part
mgorny Feb 1, 2025
704d1a5
Apply suggestions from code review
mgorny Feb 1, 2025
e596609
Remove duplicate paragraph
mgorny Feb 1, 2025
169281d
Clarify source distributions
mgorny Feb 1, 2025
bb8ac35
Add non-reproducibility argument for changing resources
mgorny Feb 1, 2025
addf891
Mention removing duplication of patches and inconsistency
mgorny Feb 2, 2025
8a3a56c
Reword installing tests to make it clearer
mgorny Feb 2, 2025
58eaf85
Give an example of "catastrophic failure"
mgorny Feb 2, 2025
76aaf79
Indicate that some distributions require building from sources
mgorny Feb 22, 2025
4f97860
Merge branch 'main' into discussion-downstream
ncoghlan Feb 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expand on downstream testing, and add emphasis for readability
  • Loading branch information
mgorny committed Jan 29, 2025
commit 9f9af53be8e3fe63af9449481b588f6642e71627
60 changes: 43 additions & 17 deletions source/discussions/downstream-packaging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,41 +233,67 @@ There is a number of things that you can do to help us test your package
better. Some of them were already mentioned in this discussion. Some examples
are:

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

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

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

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

- Do not assume that the test suite will be run with ``-Werror``. Downstreams
- **If your package has optional dependencies, make their tests optional as
well.** Either skip them if the needed packages are not installed, or add
markers to make deselecting easy.

- More generally, **add markers to tests with special requirements**. These can
include e.g. significant space usage, significant memory usage, long runtime,
incompatibility with parallel testing.

- **Do not assume that the test suite will be run with -Werror.** Downstreams
often need to disable that, as it causes false positives, e.g. due to newer
dependency versions. Assert for warnings using ``pytest.warns()`` rather
than ``pytest.raises()``!

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

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

- If your test suite takes significant time to run, **support testing
in parallel.** Downstreams often maintain a large number of packages,
and testing them all takes a lot of time. Using pytest-xdist_ can help them
avoid bottlenecks.

- Ideally, **support running your test suite via PyTest**. PyTest_ has many
command-line arguments that are truly helpful to downstreams, such as
the ability to conveniently deselect tests, rerun flaky tests
(via pytest-rerunfailures_), add a timeout to prevent tests from hanging
(via pytest-timeout_) or run tests in parallel (via pytest-xdist_).


.. _responses: https://pypi.org/project/responses/
.. _vcrpy: https://pypi.org/project/vcrpy/
.. _pytest-socket: https://pypi.org/project/pytest-socket/
.. _pytest-xdist: https://pypi.org/project/pytest-xdist/
.. _pytest: https://pytest.org/
.. _pytest-rerunfailures: https://pypi.org/project/pytest-rerunfailures/
.. _pytest-timeout: https://pypi.org/project/pytest-timeout/