s
March 23, 2024, 7:44 p.m. |

Simon Willison's Weblog simonwillison.net

time-machine example test for a segfault in Python


Here's a really neat testing trick by Adam Johnson. Someone reported a segfault bug in his time-machine library. How you you write a unit test that exercises a segfault without crashing the entire test suite?


Adam's solution is a test that does this:


subprocess.run([sys.executable, "-c", code_that_crashes_python], check=True)


sys.executable is the path to the current Python executable - ensuring the code will run in the same virtual environment as the test suite itself. …

adam example library machine python solution test testing trick

Software Engineer for AI Training Data (School Specific)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Python)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Tier 2)

@ G2i Inc | Remote

Data Engineer

@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania

Artificial Intelligence – Bioinformatic Expert

@ University of Texas Medical Branch | Galveston, TX

Lead Developer (AI)

@ Cere Network | San Francisco, US