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
Add a section on downstream testing
  • Loading branch information
mgorny committed Jan 28, 2025
commit be242a80635933692d238bb7e74c3ea962b480df
79 changes: 79 additions & 0 deletions source/discussions/downstream-packaging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,82 @@ on, and a particular dependency is either missing or incompatible, the build
should fail with an explanatory message, giving the packager an explicit
indication of the problem and a chance to consciously decide on the preferred
course of action.


.. _Support downstream testing:

Support downstream testing
--------------------------
A variety of downstream projects run some degree of testing on the packaged
Python projects. Depending on the particular case, this can range from minimal
smoke testing to comprehensive runs of the complete test suite. There can
be various reasons for doing this, for example:

- Verifying that the downstream packaging did not introduce any bugs.

- Testing on a platform that is not covered by upstream testing.

- Finding subtle bugs that can only be reproduced on a particular hardware,
system package versions, and so on.

- Testing the released package against newer dependency version than the ones
present during upstream release testing.

- Testing the package in an environment closely resembling the production
setup. This can detect issues caused by nontrivial interactions between
different installed packages, including packages that are not dependencies
of your package, but nevertheless can cause issues.

- Testing the released package against newer Python versions (including newer
point releases), or less tested Python implementations such as PyPy.

Admittedly, sometimes downstream testing may yield false positives or
inconvenience you about scenarios that you are not interested in supporting.
However, perhaps even more often it does provide early notice of problems,
or find nontrivial bugs that would otherwise cause issues for your users
in production. And believe me, the majority of downstream packagers are doing
their best to double-check their results, and help you triage and fix the bugs
that they report.

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
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!

- 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 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
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.

- 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.


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