summaryrefslogtreecommitdiffstats
path: root/pybuild-autopkgtest.rst
blob: 76da53dc2c22f2e30918a2a90557b67b2cc1bb7f (plain)
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
=====================
 pybuild-autopkgtest
=====================

----------------------------------------------------------------------------------------------------
invokes the test suite against requested Python versions and installed packages
----------------------------------------------------------------------------------------------------

:Manual section: 1
:Author: Antonio Terceiro, 2021

SYNOPSIS
========
  pybuild-autopkgtest

OPTIONS
=======

`pybuild-autopkgtest` takes no options or arguments. All configuration is done
via the same mechanisms you use to control `pybuild` itself, namely by having
build dependencies on the right packages, or by setting `PYBUILD_*` environment
variables in `debian/rules`.

DESCRIPTION
===========

`pybuild-autopkgtest` is an autopkgtest test runner that reuses all the
`pybuild` infrastructure to run tests against installed packages, as expected
by autopkgtest. To enable `pybuild-autopkgtest` for your package, you need to
add **Testsuite: autopkgtest-pkg-pybuild** to the source stanza in
`debian/control`. This will cause autodep8(1) to produce the correct contents
for `debian/tests/control`.

`pybuild-autopkgtest` will run the tests in exactly the same way as `pybuild`
will during the build, with the exception that the tests are not run in the
build directory. The test files are copied to a temporary directory, so that
the tests will run against the installed Python modules, and not against
anything in the source tree.

All the pybuild infrastructure is used, so for most packages you don't need to
add any extra code configure for `pybuild-autopkgtest`. For example, just
having a `python3-pytest` as a build dependency is enough to make the test
runner use `pytest` to run the tests.

The tests are executed via a temporary makefile that includes `debian/rules`
from the package, so that any environment variables defined there will also be
available during autopkgtest, including but not limited to `PYBUILD_*`
variables for configuring the behavior of `pybuild` itself.

ADOPTING PYBUILD-AUTOPKGTEST
============================

Since `pybuild-autopkgtest` reuses environment variables set in `debian/rules`,
migrating packages to use `pybuild-autopkgtest` should not require much effort.

You might have a `debian/tests/control` that duplicates what
`pybuild-autopkgtest` already does, e.g. copying the test files to a temporary
directory, changing to it, and running the tests from there. Such test entries
can usually be removed in favor of adding **Testsuite:
autopkgtest-pkg-pybuild** to `debian/control`.

In general, you want to move any test-related command line arguments to pybuild
into environment variables in `debian/rules`.

You can also have specialized, manually-written test cases, alongside the ones
autogenerated by `autodep8`. For this, both set **Testsuite:
autopkgtest-pkg-pybuild** in `debian/control` and keep your custom tests in
`debian/tests/control`.

VARYING BEHAVIOR UNDER AUTOPKGTEST
==================================

Ideally, the behavior of the tests should be the same during the build and
under autopkgtest, except for the fact that during autopkgtest the tests should
load the code from the installed package. `pybuild-autopkgtest` should do this
correctly most of the time.

There are situations, however, in which you need a slightly different behavior
during the autopkgtest run. There are a few mechanisms to support that:

- `pybuild-autopkgtest` sets the `PYBUILD_AUTOPKGTEST` environment variable to
  `1` during the test run. This way, you can add conditional behavior in
  `debian/rules`.
- Before and after running the tests, `pybuild-autopkgtest` will call the
  `debian/rules` targets `before-pybuild-autopkgtest` and
  `after-pybuild-autopkgtest`, respectively, if they exist.

SAMPLE TEST CONTROL FILE
========================

The control file produced by autodep8(1) looks like this::

    Test-Command: pybuild-autopkgtest
    Depends: @, @builddeps@,
    Restrictions: allow-stderr, skippable,
    Features: test-name=pybuild-autopkgtest

You should never need to hardcode this in `debian/tests/control`. You can add
extra items to `Restrictions` and `Depends` by providing a configuration file
for `autodep8` (`debian/tests/autopkgtest-pkg-pybuild.conf`) like this::

    extra_depends=foo, bar
    extra_restrictions=isolation-container, breaks-testbed

SEE ALSO
========
* pybuild(1)
* autopkgtest(1)
* autodep8(1)