Skip to main content

pytest-sigil

License: MIT Python: ^3.10

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:

  1. Execute fixture teardown code
  2. Run cleanup callbacks
  3. 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, SIGTERM won'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)

Source distribution for pytest-sigil 1.1.0
File Size Uploaded
pytest_sigil-1.1.0.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-sigil 1.1.0
File Interpreter ABI Platform
pytest_sigil-1.1.0-py3-none-any.whl Python 3 none any Details

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 log

Release 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 log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page