|
| 1 | +--- |
| 2 | +title: test |
| 3 | +date: 2025-09-15 |
| 4 | +sidebar_position: 8 |
| 5 | +--- |
| 6 | + |
| 7 | +# `packit test` |
| 8 | + |
| 9 | +Run tmt tests locally using content from the upstream repository, mimicking the behavior of the tmt functionality. |
| 10 | + |
| 11 | +By default, if no RPM paths are passed, packit builds RPMs from the current repository's source code using `mock`, then runs tmt tests in a container environment. This enables local debugging and iteration without requiring commits or CI pipeline triggers. |
| 12 | + |
| 13 | +You can override test behavior and build configuration directly from the command line using various options like `--target`, `--plans`, `--rpm-paths`, and `--clean-before`/`--no-clean-before`. |
| 14 | + |
| 15 | +The command supports two main workflows: |
| 16 | + |
| 17 | +- Auto-build workflow: Build RPMs from source code and run tmt tests on the built RPM. This is triggered when there's no `--rpm-paths` passed via the CLI. |
| 18 | +- Pre-built RPM workflow: Test existing RPM files, Paths to the RPMs are passed with the `--rpm-paths` option. |
| 19 | + |
| 20 | +## Requirements |
| 21 | + |
| 22 | +* Upstream project is using git. |
| 23 | +* Packit config file placed in the upstream repository. |
| 24 | +* `tmt` (Test Management Tool) available in the system. |
| 25 | +* Mock build system configured (for auto-build workflow). |
| 26 | + |
| 27 | +## Tutorial |
| 28 | + |
| 29 | +1. Place a config file for packit in the root of your upstream repository. |
| 30 | + |
| 31 | + |
| 32 | +2. Basic local testing (auto-build workflow): |
| 33 | + ``` |
| 34 | + $ packit test |
| 35 | + Building SRPM... |
| 36 | + Running mock build for target fedora-rawhide-x86_64... |
| 37 | + Generated RPMs: my-package-1.0-1.fc40.x86_64.rpm |
| 38 | + Running tmt tests... |
| 39 | + summary: 3 tests executed, 3 passed |
| 40 | + ``` |
| 41 | +
|
| 42 | +
|
| 43 | +3. Auto build workflow with Test on specific target: |
| 44 | + ``` |
| 45 | + $ packit test --target fedora:39 |
| 46 | + Building SRPM... |
| 47 | + Running mock build for target fedora-39-x86_64... |
| 48 | + Generated RPMs: my-package-1.0-1.fc39.x86_64.rpm |
| 49 | + Running tmt tests on fedora:39... |
| 50 | + summary: 3 tests executed, 3 passed |
| 51 | + ``` |
| 52 | +
|
| 53 | +4. Test pre-built RPMs: |
| 54 | +
|
| 55 | + ``` |
| 56 | + $ packit test --rpm-paths ./my-package-1.0-1.rpm |
| 57 | + Running tmt tests with provided RPMs... |
| 58 | + summary: 3 tests executed, 3 passed |
| 59 | + ``` |
| 60 | +
|
| 61 | +5. Test specific plans only: |
| 62 | +
|
| 63 | + ``` |
| 64 | + $ packit test --plans smoke-tests |
| 65 | + Building SRPM... |
| 66 | + Running mock build for target fedora-rawhide-x86_64... |
| 67 | + Generated RPMs: my-package-1.0-1.fc40.x86_64.rpm |
| 68 | + Running tmt plans: smoke-tests, integration... |
| 69 | + summary: 5 tests executed, 5 passed |
| 70 | + ``` |
| 71 | +
|
| 72 | +6. Skip cleanup of tmt artifacts for faster iteration: |
| 73 | + ``` |
| 74 | + $ packit test --no-clean-before --target centos:stream9 |
| 75 | + Skipping tmt cleanup... |
| 76 | + Building SRPM... |
| 77 | + Running mock build for target centos-stream-9-x86_64... |
| 78 | + Generated RPMs: my-package-1.0-1.el9.x86_64.rpm |
| 79 | + Running tmt tests on centos:stream9... |
| 80 | + summary: 3 tests executed, 3 passed |
| 81 | + ``` |
| 82 | + NB: This may cause some side effects like disk space exhaustion. |
| 83 | +
|
| 84 | +## Help |
| 85 | +
|
| 86 | + Usage: packit test [OPTIONS] |
| 87 | +
|
| 88 | + Run tmt tests locally using content from the upstream repository. |
| 89 | + |
| 90 | + This command builds RPMs from the current repository state and runs |
| 91 | + tests in containerized environments, mimicking Packit's testing service |
| 92 | + behavior for local debugging and development. |
| 93 | +
|
| 94 | + Options: |
| 95 | + --rpm-paths PATH Path to RPM file(s) to test. Can be used |
| 96 | + multiple times. If not provided, RPMs will |
| 97 | + be built automatically from source. |
| 98 | + --target TEXT Container image for testing environment |
| 99 | + (e.g., 'fedora:39', 'centos:stream9'). |
| 100 | + Defaults to 'fedora:rawhide'. |
| 101 | + --plans TEXT tmt plan name(s) to execute. Can be used |
| 102 | + multiple times to run specific plans only. |
| 103 | + If not specified, all plans are executed. |
| 104 | + --clean-before / --no-clean-before |
| 105 | + Run 'tmt clean --all' before starting the |
| 106 | + test. Defaults to disabled for clean test |
| 107 | + environments. |
| 108 | + -h, --help Show this message and exit. |
0 commit comments