pytest-sigil
Proper fixture resource cleanup by handling signals
A pytest plugin that ensures your test fixtures clean up properly when receiving termination signals (SIGTERM),
preventing resource leaks and ensuring graceful shutdowns.
Problem
When pytest receives a SIGTERM signal (e.g., from cancelled CI/CD jobs),
it terminates immediately without running fixture teardown code. This can leave resources dangling:
- Database connections remain open
- Temporary files aren't cleaned up
- Docker containers keep running
- File locks persist
Related: See pytest issues #5243 & #9142 for discussion on this behavior.
Solution
pytest-sigil intercepts SIGTERM signals and reroutes them to SIGINT handlers, allowing pytest to:
- Execute fixture teardown code
- Run cleanup callbacks
- Exit gracefully with proper status codes
Installation
pip install pytest-sigil
Usage
The plugin activates automatically once installed—no configuration needed.
import pytest
@pytest.fixture
def database_connection():
conn = create_connection()
yield conn
conn.close() # ✓ Now runs even on SIGTERM
Disable the Plugin
If needed, disable it for specific test runs:
pytest -p no:sigil
CI/CD Configuration
⚠️ Important: Requires proper signal forwarding in containerized environments. Without an init process,
SIGTERMwon't reach pytest.
GitLab CI
variables:
FF_USE_INIT_WITH_DOCKER_EXECUTOR: "true"
This flag ensures GitLab's Docker executor uses an init process (tini) that properly forwards SIGTERM to pytest.
See GitLab's feature flag documentation for details.
Note: Without proper signal forwarding, the plugin cannot intercept
SIGTERM. Check your CI provider's documentation for signal handling behavior.
How It Works
# On session start: SIGTERM → SIGINT
signal.signal(signal.SIGTERM, signal.getsignal(signal.SIGINT))
# On session finish: Restore original SIGTERM handler
signal.signal(signal.SIGTERM, original_handler)
This simple rerouting leverages pytest's existing interrupt handling, ensuring all cleanup hooks execute properly.
License
MIT © lovetheguitar
Metadata
Release files for pytest-sigil 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_sigil-1.1.0.tar.gz | 3.4 kB | With provenance | Details for pytest_sigil-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_sigil-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for pytest_sigil-1.1.0-py3-none-any.whl |
Total release size: 7.2 kB
Release files / pytest_sigil-1.1.0.tar.gz
| Download URL | pytest_sigil-1.1.0.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ddfd9aa2ce8cc85b9518a864d73e3572a7c5e8968e78e81cb4057289478325d
|
|
BLAKE2b-256 checksum How to use checksums |
b0134a00f9b934a6ac1b14cc7803cf11dcd8097ab20d07980651ba32e4334d77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logRelease files / pytest_sigil-1.1.0-py3-none-any.whl
| Download URL | pytest_sigil-1.1.0-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ac5ca111bb89f45617f806cf1c8513dae3ef8a2fc10b2ba547d1c193a2cfc7e
|
|
BLAKE2b-256 checksum How to use checksums |
99d3c93ac37ba93d332566216f5d12874fe8a6dd187cbf2247eedbf09b222c72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logSecurity for pytest-sigil 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pytest_sigil-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.