A pytest plugin that prevents crashes from killing your test suite, with execution tracing
Project description
pytest-fkit
Fix Krashes In Tests - A pytest plugin that prevents crashes from killing your entire test suite.
When a test crashes Python (SIGABRT, SIGSEGV, etc.), it catches the crash and converts it to a normal pytest ERROR instead of killing your entire test run.
The Problem
When running large test suites (like HuggingFace Transformers), sometimes a test causes Python to crash with a signal like SIGABRT:
Fatal Python error: Aborted
Thread 0x0000799e2ea00640 (most recent call first):
File "/transformers/src/transformers/models/dots1/modeling_dots1.py", line 331 in forward
...
This kills pytest entirely, and all remaining tests in your suite never run.
The Solution
pytest-fkit runs each test in an isolated subprocess. If a test crashes:
- ✅ The crash is caught and reported as a pytest ERROR
- ✅ The remaining tests continue running
- ✅ You get a full report with all test results, including which ones crashed
Installation
cd pytest-fkit
pip install -e .
Or install from your test requirements:
pip install pytest-fkit
Usage
Basic Usage
Just add the --fkit flag to your pytest command:
pytest --fkit
With Timeout
Set a timeout per test (default is 600 seconds / 10 minutes):
pytest --fkit --fkit-timeout=300 # 5 minute timeout per test
# In transformers_ut.sh
pytest --fkit --fkit-timeout=600 tests/
Skip Crash Isolation for Specific Tests
If you have tests that don't play well with subprocess isolation, mark them:
import pytest
@pytest.mark.fkit_skip
def test_something_special():
# This test will run normally without subprocess isolation
pass
How It Works
- Subprocess Isolation: Each test runs in its own Python subprocess
- Signal Detection: When a subprocess is killed by a signal (negative return code), we detect it
- Error Conversion: Crashes are converted to pytest ERROR results with full output
- Continuation: The main pytest process continues with remaining tests
Example Output
tests/models/dots1/test_modeling_dots1.py::Dots1ModelTest::test_forward PASSED
tests/models/dots1/test_modeling_dots1.py::Dots1ModelTest::test_model_15b_a2b_generation 💥
======================================================================
💥 TEST CRASHED: SIGABRT (Aborted)
======================================================================
This test caused Python to crash with SIGABRT (Aborted).
pytest-fkit caught it and converted it to an ERROR.
--- STDOUT ---
...test output...
--- STDERR ---
Fatal Python error: Aborted
...crash traceback...
======================================================================
tests/models/dots1/test_modeling_dots1.py::Dots1ModelTest::test_backward PASSED
=============== pytest-fkit summary ===============
💥 1 test(s) CRASHED (converted to ERROR by pytest-fkit):
- tests/models/dots1/test_modeling_dots1.py::Dots1ModelTest::test_model_15b_a2b_generation
✅ pytest-fkit prevented 1 crashes from killing your test suite!
Performance Considerations
- Overhead: Running each test in a subprocess adds overhead (~100-500ms per test)
- Best For: Large test suites where crashes are occasional but catastrophic
- Not Recommended: Tiny test suites with < 100 tests where crashes are rare
For the HuggingFace Transformers test suite with 100,000+ tests, the overhead is worth it to ensure all tests run to completion.
Configuration
You can also enable pytest-fkit in pytest.ini or pyproject.toml:
# pytest.ini
[pytest]
addopts = --fkit --fkit-timeout=600
# pyproject.toml
[tool.pytest.ini_options]
addopts = ["--fkit", "--fkit-timeout=600"]
Compatibility
- Python 3.8+
- pytest 6.0+
- Linux, macOS (Windows support TBD)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_fkit-0.1.0.tar.gz.
File metadata
- Download URL: pytest_fkit-0.1.0.tar.gz
- Upload date:
- Size: 72.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
520f196e51c3470d5858b3d92f80bf72e92f9e31e45b8045396e4bb02d7d3d0c
|
|
| MD5 |
f343c4b84fd32d6d1855aebc688d86f1
|
|
| BLAKE2b-256 |
d31b2e5e13f58b79dea285a944b55e30fb8ae5ef8e544029e2b1d3cb221819cc
|
File details
Details for the file pytest_fkit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_fkit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 80.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e6003600a5e29b1f1ea81cd6f7dcab8489188a6d0c77afe541dee10a7182425
|
|
| MD5 |
ef4397b3a25311b9e040b83961daefc9
|
|
| BLAKE2b-256 |
5b522dda59063273ad31cb8d0e68ab8d86f99dda65b515a6b9de1124ad6774a9
|